world.DoAfter

Posted by Hoss on Mon 06 Dec 2004 01:26 AM — 3 posts, 13,444 views.

USA #0
I'm working with a world.DoAfter and this is what it's going through

world.setvariable "ginp", cint(world.getvariable ("ginp")) -1

if @ginp = "20" or @ginp < "20" then
world.note "Time To Change Plants"
Elseif @ginp > "20" then
world.DoAfter 4, "hgi"
end if

But I seem to find that the DoAfter is firing once more time than it should be if it's set for 20 but if I set it for 21 it doesn't send that extra time any idea why?

Hoss
Australia Forum Administrator #1
This code looks a bit strange.

  • There is a "less than or equal" operator (<=) so you don't need to separately test for less OR equal. Thus I would rewrite:


    if @ginp = "20" or @ginp < "20" then


    as


    if @ginp <= "20" then

  • I don't see the point in then testing for:


    Elseif @ginp > "20" then


    Surely if something is not less than or equal to 20, it must be greater than? So that can just be a straight "else".
  • You are comparing numbers to strings. I would rewrite it as:

    
    If @ginp <= 20 Then
      world.Note "Time To Change Plants"
    Else 
      world.DoAfter 4, "hgi"
    end if
    



Finally the real problem. When you use @ginp as a variable in your trigger, MUSHclient will substitute the current value of the variable "ginp" into the "send to" box, and then execute the script.

Subtracting 1 in the script itself is too late. The substitution has already been done.

What you could do instead is:



SetVariable "ginp", cint(GetVariable ("ginp")) -1

If CInt(GetVariable ("ginp")) <= 20 Then
  Note "Time To Change Plants"
Else 
  DoAfter 4, "hgi"
end if
USA #2
Or you could just account for that 1 being subracted, and compare it to 21 (which is what the variable is before you subtract, to get to 20).

You should probably subtract from the variable after the if statement, to keep yourself from being confused later.