Else/If statements issue

Posted by Traz on Mon 05 Mar 2018 01:53 AM — 11 posts, 30,958 views.

#0
So I'm having an issue with a script and I'm not sure what's wrong. I've tried a few different formats but to save space I'm only going to share the first one because none of my transmutations worked anyways.


require "wait"
  if @Ki <= 100000 else
  if @Pl <= 500000 then
  if lastTriggerTime == nil or os.time () - lastTriggerTime >= 10 then
wait.make (function ()
  lastTriggerTime = os.time ()
Execute ("nmoff")
wait.time (10)
Execute ("senzu")
wait.time (2)
Execute ("nmon")
end)
end
end


At line 2, I get 'then' expected near 'else' but I can't for the life of me figure out how to fix it.
USA Global Moderator #1
Please fix the code indentation so that we can better guess what you're trying to do.

What do you expect "if @Ki <= 100000 else" to do?
#2
What I want is to check if Ki is lower than the amount OR if Pl is lower than the amount, do the actions beneath.
Australia Forum Administrator #3
In that case don't you mean:


  if @Ki <= 100000 or @Pl <= 500000 then
#4
That gives the error: [string "Trigger: "]:2: unexpected symbol near 'if'
USA Global Moderator #5
Traz said:

That gives


Always show the code that generates an error please. :)

Also, I absolutely hate @-notation instead of GetVariable. It frequently causes problems for new scripters because of when the @ is parsed.

What happens if you use this?


require "wait"
local Ki = tonumber(GetVariable("Ki"))
local Pl = tonumber(GetVariable("Pl"))
if (Ki <= 100000) or (Pl <= 500000) then
  if (lastTriggerTime == nil) or ((os.time() - lastTriggerTime) >= 10) then
    wait.make (function()
      lastTriggerTime = os.time()
      Execute("nmoff")
      wait.time(10)
      Execute("senzu")
      wait.time(2)
      Execute("nmon")
    end)
  end
end
Amended on Mon 05 Mar 2018 05:14 AM by Fiendish
#6
With the new GetVariable script:
Run-time error
World: DragonBall Evolution
Immediate execution
[string "Trigger: "]:4: attempt to compare string with number
stack traceback:
[string "Trigger: "]:4: in main chunk
Amended on Mon 05 Mar 2018 05:16 AM by Traz
USA Global Moderator #7
Traz said:


  if @Ki &lt;= 50000 or if @Pl &lt;= 500000 then




"if A or B then" not "if A or if B then"
USA Global Moderator #8
Quote:
[string "Trigger: "]:4: attempt to compare string with number

Try it again. I think our boats crossed paths in the night. The current version uses tonumber.
Amended on Mon 05 Mar 2018 05:26 AM by Fiendish
#9
It started working when I took the second 'if' out of line two, that was my fault.

Thanks for the help you guys. I just did a stupid.
Australia Forum Administrator #10
Traz said:

That gives the error: [string "Trigger: "]:2: unexpected symbol near 'if'


You probably saw:


  if @Ki <= 100000 or @Pl <= 500000 then


But decided to ignore that and typed:


  if @Ki <= 100000 or if @Pl <= 500000 then