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
➜ Using a variable in if
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Meraki
(7 posts) Bio
|
| Date
| Fri 30 May 2014 01:48 PM (UTC) Amended on Fri 30 May 2014 01:54 PM (UTC) by Meraki
|
| Message
| I'm having trouble with an if statement firing when comparing variables. Here's what I have:
<triggers>
<trigger
enabled="y"
match="Look in the general vicinity of * for *!"
send_to="12"
sequence="100"
>
<send>SetVariable ("location", "%1")
SetVariable ("room", "%2")
ColourNote ("black", "white", "Location: %1 Room: %2")
-- Location Jovar
if "%1" == "Jovar" then
ColourNote("black", "white", "Location Recognized: @location")
Execute("#4s 3e 3n 3w 3n e (up)")
Execute("enter icewall")
Execute("c fly")
Execute("#2(nw) 2w (nw) n (nw) e n 2(u) w 2(up)")
if "%2" == "Smithy" then
ColourNote("black", "white", "Room confirmed: @room")
Execute("#5n 2e n")
if "@quest_item" == "the crown jewels" then
Execute("get crown$recall$north$north$pq complete")
elseif "@quest_item" == "blue diamond shard" then
Execute("get shard$recall$north$north$pq complete")
elseif "@quest_item" == "bright green emerald" then
Execute("get emerald$recall$north$north$pq complete")
elseif "@quest_item" == "lost puppy" then
Execute("get puppy$recall$north$north$pq complete")
end -- quest_item if
end -- room if
if "%2" == "The Planning Room" then
ColourNote("black", "white", "Room confirmed: @room")
Execute("#5n 2e n")
Execute("open west")
Execute("west")
if "@quest_item" == "the crown jewels" then
Execute("get crown$recall$north$north$pq complete")
elseif "@quest_item" == "blue diamond shard" then
Execute("get shard$recall$north$north$pq complete")
elseif "@quest_item" == "bright green emerald" then
Execute("get emerald$recall$north$north$pq complete")
elseif "@quest_item" == "lost puppy" then
Execute("get puppy$recall$north$north$pq complete")
end -- quest_item if
end -- room if
end -- location if</send>
</trigger>
</triggers>
This solution works because it's working directly with the wildcards that are being sent in. What I want to work is this:
ColourNote ("black", "white", "Location: %1 Room: %2")
-- Location Jovar
if "@location" == "Jovar" then
As I understand it, it's supposed to compare the variable location to the word Jovar however the statement doesn't fire. I've considered using getVariable but I'm not sure how things are stored in a variable.
Could someone clear this up for me as to why this isn't matching?
Thank you in advance. | | Top |
|
| Posted by
| Meraki
(7 posts) Bio
|
| Date
| Reply #1 on Fri 30 May 2014 02:52 PM (UTC) |
| Message
| I have an update from searching around a little more extensively is it possible to use the string.match?
The code would look something like this:
if string.match(@location, "Jovar") then
--Do stuff | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Sat 31 May 2014 03:08 AM (UTC) |
| Message
|
SetVariable ("location", "%1")
...
ColourNote("black", "white", "Location Recognized: @location")
Your problem here is that variable substitution is done before the script executes. That is, @location is replaced by the contents of the "location" variable before anything is executed.
Thus the new value (%1) will not be used.
You are better off using Lua variables, or using GetVariable.
eg. Lua variables:
location = "%1"
...
ColourNote("black", "white", "Location Recognized: " .. location)
or using GetVariable:
SetVariable ("location", "%1")
...
ColourNote("black", "white", "Location Recognized: " .. GetVariable ("location"))
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
12,480 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top