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
➜ hmm, what have I stuffed up? (AddTriggerEx question)
hmm, what have I stuffed up? (AddTriggerEx question)
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Wyd
(14 posts) Bio
|
Date
| Sun 18 Jun 2006 03:47 AM (UTC) |
Message
| Ok, I have just started playing around with lua coding, and need to create a trigger within a function... I came up with this:
AddTriggerEx(id,currentroom,
"WORM WARP TO " .. string.upper (destination),
trigger_flag.Enabled or trigger_flag.RegularExpression,
custom_colour.NoChange,0," "," ",2,100)
id, currentroom and destination all have values, and the function seems to work without a problem...except the trigger doesn't seem to work.
Also, if I create a trigger like this, will it be saved within the plugin when I close mushclient?
Thanks in advance for the help
Wyd | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Sun 18 Jun 2006 04:22 AM (UTC) |
Message
| This line is probably the problem: trigger_flag.Enabled or trigger_flag.RegularExpression .
For starters, you need to have those as the flags, but you probably have that already.
But more importantly, or in Lua is the binary or, not the bitwise or. Look at this example:$ lua
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> =(1 or 2)
1
>
We should have gotten 3, not 1, but since it's binary, we got 1.
If you can guarantee that the operands in your expression will all be powers of 2 -- flags, never combinations of flags -- you can simply sum them instead of trying to combine them with bit operations.
You can also extend Lua with bitwise operators, as described in this tutorial:
http://lua-users.org/wiki/BinaryModuleTutorial
Maybe if you ask Nick nicely, he can include the bitwise library as a default extension to the Lua environment. :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sun 18 Jun 2006 04:38 AM (UTC) Amended on Sun 18 Jun 2006 04:39 AM (UTC) by Nick Gammon
|
Message
| To troubleshoot you should get the return value from the call.
eg.
id = "test"
currentroom = "blah"
destination = "somewhere"
print (
AddTriggerEx(id,currentroom,
"WORM WARP TO " .. string.upper (destination),
trigger_flag.Enabled or trigger_flag.RegularExpression,
custom_colour.NoChange,0," "," ",2,100)
)
This prints 30009. That tells you that the call failed with error code 30009. You can look that up in the documentation, or use the "check" function supplied in the exampscript.lua file:
id = "test"
currentroom = "blah"
destination = "somewhere"
check (
AddTriggerEx(id,currentroom,
"WORM WARP TO " .. string.upper (destination),
trigger_flag.Enabled or trigger_flag.RegularExpression,
custom_colour.NoChange,0," "," ",2,100)
)
Opens dialog:
[string "Immediate"]:5: Script name is not in the script file
Your problem here is that the script suboutine name you have given is " " (note the space). If you want no script it must be "" (no space - that is, an empty name).
Your other problem is that the expression:
trigger_flag.Enabled or trigger_flag.RegularExpression
... won't do what you expect. Try printing it:
print (trigger_flag.Enabled or trigger_flag.RegularExpression) --> 1
In Lua the "or" is a logical or, not a bitwise or. You should do one of two things here:
bit.bor (trigger_flag.Enabled, trigger_flag.RegularExpression) --> 33
That does a bitwise "or" and uses the "bit" library included with MUSHclient. Or, perhaps more simply, just add them together:
trigger_flag.Enabled + trigger_flag.RegularExpression --> 33
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 18 Jun 2006 04:40 AM (UTC) |
Message
|
Quote:
Also, if I create a trigger like this, will it be saved within the plugin when I close mushclient?
No, plugins do not extend themselves like this. Plugins can be shared between worlds, and only the variables are saved to the plugin "state" file.
If plugins need to create triggers "on the fly" they will have to recreate them each time. You could use ExportXML to save the trigger (into a variable for example) and ImportXML to put it back next time. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #4 on Sun 18 Jun 2006 04:41 AM (UTC) |
Message
| (There should be a way to see easily that somebody replied while you were posting... hmm.)
Looks like Nick already included the bitwise libraries; that's good, since it makes it much easier to solve this problem. :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sun 18 Jun 2006 04:41 AM (UTC) |
Message
|
Quote:
Maybe if you ask Nick nicely, he can include the bitwise library as a default extension to the Lua environment
See:
http://www.gammon.com.au/scripts/doc.php?general=lua
Look for the "Bit manipulation library" in there. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #6 on Sun 18 Jun 2006 07:20 AM (UTC) |
Message
| Heh, we made about 3 posts right past each other. :-)
Quote: Looks like Nick already included the bitwise libraries; I've never seen a forum that notified users of posts made while they were writing a post. It would prevent a fair amount of missing posts because you thought you were the last to say something. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | 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.
20,385 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top