Post new topic    
Liquid Metal Slime
Send private message
Problem with Timer Script 
 PostWed Jan 13, 2010 5:49 pm
Send private message Reply with quote
Code:
      if (level == 1 && get npc id (20) == -1 && get npc id (21) == -1 && get npc id (22) == -1) then (
         set timer (15,5,18,@resetmobs)   
      )


What confuses me about this is that I know the IF statement is being read correctly because I can put the @script code into the THEN block directly and it runs fine. The problem with that is the fact that I can't have a countdown time before it is ran that way.

Any idea why the timer is not triggering the script properly?
Cornbread Chemist
Liquid Metal Slime
Send private message
 
 PostWed Jan 13, 2010 7:49 pm
Send private message Reply with quote
If it helps, here is the script that is supposed to be run after the timer expires:

Code:
plotscript,resetmobs,begin
   respawncount += 1
   if (level == 1) then (
      powerx := random(1,15)
      powery := random (1,9)
      create npc (20,powerx,powery)
      alter NPC (20,NPCstat:move type,npcmovetype:pace)
      alter npc (20,NPCstat:picture,5)
      while (check npc wall (20,north) ,or, check npc wall (20,south) ,or, check npc wall (20,east) ,or, check npc wall (20,west)) do (
         destroy npc (20)
         powerx := random(1,15)
         powery := random (1,9)
         create npc (20,powerx,powery)
         alter NPC (20,NPCstat:move type,npcmovetype:pace)
         alter npc (20,NPCstat:picture,5)
      )
      powerx := random(1,15)
      powery := random (1,9)
      create npc (21,powerx,powery)
      alter NPC (21,NPCstat:move type,npcmovetype:pace)
      alter npc (21,NPCstat:picture,5)
      while (check npc wall (21,north) ,or, check npc wall (21,south) ,or, check npc wall (21,east) ,or, check npc wall (21,west)) do (
         destroy npc (21)
         powerx := random(1,15)
         powery := random (1,9)
         create npc (21,powerx,powery)
         alter NPC (21,NPCstat:move type,npcmovetype:pace)
         alter npc (21,NPCstat:picture,5)
      )
      powerx := random(1,15)
      powery := random (1,9)
      create npc (22,powerx,powery)
      alter NPC (22,NPCstat:move type,npcmovetype:pace)
      alter npc (22,NPCstat:picture,5)
      while (check npc wall (22,north) ,or, check npc wall (22,south) ,or, check npc wall (22,east) ,or, check npc wall (22,west)) do (
         destroy npc (22)
         powerx := random(1,15)
         powery := random (1,9)
         create npc (22,powerx,powery)
         alter NPC (22,NPCstat:move type,npcmovetype:pace)
         alter npc (22,NPCstat:picture,5)
      )
   )
end

Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostWed Jan 13, 2010 9:31 pm
Send private message Reply with quote
If the set timer command keeps getting run again before the timer runs out, then the timer would never finish.

What if you do:

Code:

    if (level == 1 && get npc id (20) == -1 && get npc id (21) == -1 && get npc id (22) == -1) then (
        if(read timer(15) == 0) then(
            set timer (15,5,18,@resetmobs)
        )
    )


I think that might work, but I have not tested it.
Liquid Metal Slime
Send private message
 
 PostWed Jan 13, 2010 10:38 pm
Send private message Reply with quote
No dice, but I did manage to figure it out!

Code:
      if (level == 1 && get npc id (20) == -1 && get npc id (21) == -1 && get npc id (22) == -1 && mobreseter == false) then (
         mobreseter := true
            set timer (12,2,18,@resetmobs)   
      )


For some reason, that portion of the script was in an infinite loop before I added that variable, therefore, the timer was never running down. It works fine now, but I'm wondering why it was in a continuous loop in the first place?
Cornbread Chemist
Metal Slime
Send private message
 
 PostWed Jan 13, 2010 11:38 pm
Send private message Reply with quote
Meatballsub wrote:
No dice, but I did manage to figure it out!

Code:
      if (level == 1 && get npc id (20) == -1 && get npc id (21) == -1 && get npc id (22) == -1 && mobreseter == false) then (
         mobreseter := true
            set timer (12,2,18,@resetmobs)   
      )


For some reason, that portion of the script was in an infinite loop before I added that variable, therefore, the timer was never running down. It works fine now, but I'm wondering why it was in a continuous loop in the first place?


Because it kept checking, and the conditions kept being true, so it kept starting the timer.

When doing an if loop, you need to have a variable for "and if we didn't already start".
Display posts from previous: