Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Boggled trying to make a Toggle
Boggled trying to make a Toggle
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Falken
(4 posts) Bio
|
Date
| Thu 08 May 2008 05:30 AM (UTC) |
Message
| Hi Nick and Co.,
First, thanks for coding a great freeware application.
I've been a lurker for a while now, and can't seem to uncover what I'm doing wrong. I'm a MC newbie, but know how to make basic aliases and triggers, and I understand (at least I thought I did) basic control.
I'm not using functions or a script file since that's over my head for now. I realise that what I want to do is easily handled with multiple aliases (like "seekon" and "seekoff"), but I'm trying to condense and thought I'd try using IF THEN ELSE.
1. I know there has to be a sexier way to do this.
2. I can't get the trigger to work.
3. Even though I don't know very much, I'm providing examples of my work--it's better than saying "Make me a trigger and some aliases that do..." right?
What I want:
Trigger
Called "seeking" that highlights output from the mud--the contents of up to three variables: seek1, seek2, seek3
Alias(es)
Called "seek" to toggle it off/on.
Enter "seek" and up to three arguments to store strings in the variables: seek1, seek2, seek3. Doing so enables the "seeking" trigger by default.
What I've tried:
The trigger:
<triggers>
<trigger
custom_colour="17"
enabled="y"
match="@seeking|@seeking2|@seeking3"
name="seeklite"
sequence="100"
other_text_colour="deeppink"
other_back_colour="#000057"
>
</trigger>
</triggers>
I made four aliases that match like this...
^seek (.*?) (.*?) (.*?)$
^seek (.*?) (.*?)$
^seek (.*?)$
^seek$
The first three capture and store the variables seek1, seek2, and seek3. They also SetVariable("seektoggle",1)
The last is supposed to toggle the trigger. I always get my fail message when I try the command.
<aliases>
<alias
match="^seek$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
local seekcheck
seekcheck = GetVariable("seektoggle")
if "seekcheck" == 1
then SetVariable("seektoggle",0)
EnableTrigger("seeklite",false)
Note""
Note" Seeking Disabled "
Note""
elseif "seekcheck" == 0
then SetVariable("seektoggle",1)
EnableTrigger("seeklite")
Note""
Note" Seeking Enabled "
Note""
else
Note" Trigger Failed "
end
</send>
</alias>
</aliases>
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 08 May 2008 05:53 AM (UTC) |
Message
|
Quote:
I'm providing examples of my work--it's better than saying "Make me a trigger and some aliases that do..." right?
Much better. :)
Quote:
seekcheck = GetVariable("seektoggle")
if "seekcheck" == 1
then
Your basic problem is here. You are comparing a string "seekcheck" to be equal to 1, which it never will be (it has the value "seekcheck").
You mean:
seekcheck = GetVariable("seektoggle")
if seekcheck == 1 then
As a style thing, I like the "then" on the same line as the "if" personally.
That way, if you want to add more things to happen if the "if" is true, you don't have to start moving the word "then" around. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Falken
(4 posts) Bio
|
Date
| Reply #2 on Thu 08 May 2008 12:08 PM (UTC) |
Message
| Thanks Nick,
Great style tip, that makes things much easier.
It's still failing after applying that fix. | Top |
|
Posted by
| Falken
(4 posts) Bio
|
Date
| Reply #3 on Thu 08 May 2008 08:21 PM (UTC) Amended on Thu 08 May 2008 08:23 PM (UTC) by Falken
|
Message
| Looking through the implemented help for "GetVariable" I found the error. What a relief!
Quote:
Variables are stored as strings, so GetVariable returns a string, not a number. If the variable is supposed to be storing a numeric quantity (a count of mobs, hit points, or experience, for example) then you will probably need to convert it back to a number if it is going to be correctly processed inside a script. For example:
Lua: x = tonumber (GetVariable ("x"))
Also, I realized that using a local variable was unnecessary and sloppy.
seektoggle = tonumber (GetVariable ("seektoggle"))
if seektoggle == 1 then
SetVariable("seektoggle",0)
EnableTrigger("seeklite",false)
Note""
Note" Seeking Enabled "
Note""
elseif seektoggle == 0 then
SetVariable("seektoggle",1)
EnableTrigger("seeklite")
Note""
Note" Seeking Disabled "
Note""
end
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #4 on Thu 08 May 2008 09:05 PM (UTC) |
Message
| Glad it works. As another style issue, try putting spaces after keywords, eventually it will bite you if you don't.
eg.
SetVariable ("seektoggle", 1)
EnableTrigger ("seeklite")
Note ""
Note " Seeking Disabled "
Note ""
That also makes it easier to read.
Is this seektoggle variable local to one session? That is, is it relevant between games (like if you log out, and connect again tomorrow)? If not, you don't need to use MUSHclient variables at all, that would look neater. For example:
if seektoggle then
seektoggle = false
EnableTrigger ("seeklite", false)
Note ""
Note " Seeking Enabled "
Note ""
else
seektoggle = true
EnableTrigger ("seeklite")
Note ""
Note " Seeking Disabled "
Note ""
end
And also in other places, simply assign true or false to seektoggle. This is using the Lua variable, which is probably all you need.
You also don't need the elseif, after all if seektoggle is not true, it must be false, right? There is no third case.
Once you get this far you can neaten it even further:
seektoggle = not seektoggle -- toggle it
EnableTrigger ("seeklite", seektoggle)
Note ""
if seektoggle then
Note " Seeking Enabled "
else
Note " Seeking Disabled "
end -- if
Note ""
See how that reduces a lot of the repetition in the script? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Falken
(4 posts) Bio
|
Date
| Reply #5 on Thu 08 May 2008 10:11 PM (UTC) Amended on Fri 09 May 2008 03:46 AM (UTC) by Falken
|
Message
| Nick,
So generous to share those techniques--thanks, thanks, and thanks again. That's a lot sexier than my cluttered attempts.
But, I expected nothing less--I'm not even in your league. That last part of code is so compact and neat. I love it.
The end result here is I learned how to properly use BOOLEAN which I couldn't quite understand. Originally I wanted to use "true" and "false" instead of variables but in the aliases I kept getting type-match errors.
Now I'm feeling compulsive about cleaning up/rearranging all the other triggers/aliases I have.
Derek Falken | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
15,880 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top