IF statement in LUA

Posted by Fawkes on Thu 11 Jan 2007 07:29 AM — 4 posts, 15,072 views.

#0
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>
Australia Forum Administrator #1
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

#2
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.
Australia Forum Administrator #3
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")