Can't figure this out

Posted by David Berthiaume on Mon 21 Feb 2005 07:11 PM — 11 posts, 42,314 views.

#0
<triggers>
  <trigger
   enabled="y"
   match="You gained a level!"
   name="GainLevel"
   send_to="12"
   sequence="2"
  >
  <send>levelold = CInt(GetVariable ("level"))
if GetVariable ("level2") = "subhero" then
level = (levelold + 1)
if level &gt; 100 then
SetVariable ("level2", "H")
level == (level - 100)
SetVariable ("level", level)
else
SetVariable ("level", level)
end
else
level = (levelold + 1)
SetVariable ("level", level)
end
</send>
  </trigger>
</triggers>



Lua Scripting, keep getting this error:
Error number: 0
Event:        Compile error
Description:  [string "Trigger: Hunger"]:5: `=' expected near `=='
Called by:    Immediate execution

I've changed all the "=" to "==" but that didn't fix it.
Amended on Mon 21 Feb 2005 07:12 PM by David Berthiaume
USA #1
Your if statement should have == in it. And all the assignments need simply a =.
You (at least what you pasted) have a == in your second assignment (when you subtract 100).
#2
Not sure if this matters or not, but it doesn't even look like the error message was for this trigger. I mean, this trigger has errors in it, too, but the message appears to be for a "Hunger" trigger.

In Lua (as in C), you use "==" for logical comparison and "=" for variable assignment. The main difference is that in Lua you'll get an error when you try to swap them around. In C, it's legal, though the logic may not be what you wanted.
#3
Doh! I copy/pasted the wrong trigger...
#4
Error number: 0
Event:        Compile error
Description:  [string "Trigger: Hunger"]:5: `=' expected near `=='
Called by:    Immediate execution


Ok, lets try this again.


<triggers>
  <trigger
   enabled="y"
   group="InfoBarScript"
   ignore_case="y"
   keep_evaluating="y"
   match="^\&lt;(.*)\%HP\|(.*)\%Mana\|(.*)\%Move\&gt; \&lt;(.*)\&gt;$"
   name="Hunger"
   omit_from_output="y"
   regexp="y"
   repeat="y"
   send_to="12"
   sequence="1"
  >
  <send>SetVariable ("aaHP", "%1")
SetVariable ("aaMana", "%2")
SetVariable ("aaMove", "%3")
SetVariable ("aaHunger", "%4")
hunger == GetVariable ("aaHunger")
if (hunger == "H") or (hunger == "T") or (hunger == "HT") then
for count == 1 to 2
SendImmediate ("drink soup")
next
else
end</send>
  </trigger>
</triggers>
USA #5
Based on what it looks like you're trying to do (no documentation leaves us guessing a little)
hunger == GetVariable ("aaHunger")
should be
hunger = GetVariable ("aaHunger")
so the variable is being set instead of evaluated. The rest of the logic looks right as far as I can tell.
#6
Tried that, Tried a lot of things. Can't get it to work.
USA #7
Your for statement should also have a = instead of a ==, since it's an assignment, not a comparison.

Why do you have the else statement?

And your end should be an "end if".

The difference between == and = is not trivial, use = when youre assigning a value, use == when you're comparing them. You had this same problem in the other script you posted, why that hasn't given you problems is just luck.

With all these syntax errors, you should download the VBScript scriptdocs (alright, so its really called Windows Script docs, but still) and reference it often (especially when debugging).
You would've seen that it says 'for counter = start to end' and that if statements have optional elses and require an 'end if' instead of merely an 'end'. So download that (you can download it from the same section as the 'script functions you can download' on the first inbuilt function page).

It's also quite possible that your trigger is wrong, or that you have leading/trailing spaces in the variable.
You also don't need to use getvariable to get the contents of aaHunger, since you have it as %4 already, that will save you time in your script. But check your hunger variable (MC variable, or even just note %4) and see if it is indeed H T or HT (without other whitespace or anything else) when you think it should be firing.
Amended on Mon 28 Feb 2005 05:03 PM by Flannel
USA #8
Oh yeah, and it just occured to me that we're in VBscript, and we dont ever use ==. So change all those (comparisons and assignments) to =. That's probably the problem that started this all.

We're all just confused as to what language we're actually writing in.
#9
I'm writing in Lua
Russia #10
The error is still clearly pointing at the "==" operator. So change:

hunger == GetVariable ("aaHunger")


to:

hunger = GetVariable ("aaHunger")


As Meerclar already said. Next, your for loop looks fishy, I think you are confusing vbs and Lua here. According to the Lua docs it should be:


for count=1,2 do
  ...
end


Not what you have:


for count == 1 to 2
   ...
next


So the script should be:


SetVariable ("aaHP", "%1")
SetVariable ("aaMana", "%2")
SetVariable ("aaMove", "%3")
SetVariable ("aaHunger", "%4")
hunger = GetVariable ("aaHunger")
if (hunger == "H") or (hunger == "T") or (hunger == "HT") then
   for count=1,2 do
      SendImmediate ("drink soup")
   end
end


Or better yet:


SetVariable ("aaHP", "%1")
SetVariable ("aaMana", "%2")
SetVariable ("aaMove", "%3")
SetVariable ("aaHunger", "%4")
hunger = "%4"
if (hunger == "H") or (hunger == "T") or (hunger == "HT") then
   for count=1,2 do
      SendImmediate ("drink soup")
   end
end