Gammon Forum
Entire forum
MUSHclient
General
IF statement in LUA
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Fawkes
(2 posts) bio
|
Date
| Thu 11 Jan 2007 07:29 AM (UTC) |
Message
| I cannot figure out what I am doing wrong on this trigger. I tried searchin through the forums for examples, and it looks as if my syntax is correct, but it mustn't be because I keep recieving this error:
Error number: 0
Event: Compile error
Description: [string "Trigger: "]:7: 'end' expected (to close 'if' at line 4) near '<eof>'
Called by: Immediate execution
This is the script I have made:
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="inscribing"
keep_evaluating="y"
match="You have successfully inscribed the image of the *"
send_to="12"
sequence="100"
>
<send>Send ("ind @typetoinscribe")
SetVariable("cardstoinscribe", GetVariable("cardstoinscribe")-1)
ColourNote ("orange", "black", "@cardstoinscribe cards left to inscribe")
if tonumber(GetVariable("cardstoinscribe")) > 0 then
if tonumber(GetVariable("mana")) > 250 then
Send("inscribe blank with @typetoinscribe")
end</send>
</trigger>
</triggers>
| top |
|
Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Date
| Reply #1 on Thu 11 Jan 2007 07:48 AM (UTC) |
Message
|
Quote:
if tonumber(GetVariable("cardstoinscribe")) > 0 then
if tonumber(GetVariable("mana")) > 250 then
Send("inscribe blank with @typetoinscribe")
end
You have 2 "if" statements but 1 "end".
You could write it like this:
if tonumber(GetVariable("cardstoinscribe")) > 0 and
tonumber(GetVariable("mana")) > 250 then
Send("inscribe blank with @typetoinscribe")
end
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Fawkes
(2 posts) bio
|
Date
| Reply #2 on Thu 11 Jan 2007 05:02 PM (UTC) |
Message
| Thanks! Worked perfectly.
I have a question relating to that same script I posted up there now. I have the part where it subtracts 1 from the cardstoinscribe variable, then ColourNotes how many cards I have left. The problem is the ColourNote always says the amount from the previous value of the variable instead of the new one. It's weird though because the rest of the script senses the real number of the variable, because, for instance, when the cardstoinscribe hits zero, the inscribing stops, but it will still ColourNote that I have 1 left to inscribe:
1140h, 890m, 4600w ex- insc 1 hermit
outd 1 blank
You shuffle 1 card with the image of nothing out of your deck.
1140h, 890m, 4600w ex-
inscribe blank with hermit
[Inscribing spam]
1140h, 390m, 4524w ex-
You have successfully inscribed the image of the Hermit on your Tarot card.
ind hermit
1 cards left to inscribe
1140h, 390m, 4536w ex-
You put 1 card with the image of the Hermit in your deck of cards.
That bold part should say zero to correspond with the real value of the variable. | top |
|
Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Date
| Reply #3 on Thu 11 Jan 2007 08:19 PM (UTC) |
Message
| The problem is this line:
ColourNote ("orange", "black", "@cardstoinscribe cards left to inscribe")
MUSHclient does variable substitution (eg. @ cardstoinscribe) before executing the script, so that value will not change. You really want:
ColourNote ("orange", "black", GetVariable ("cardstoinscribe") .. " cards left to inscribe")
|
- 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.
10,186 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.