• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] I need to mess up this code (really)

Status
Not open for further replies.
Level 6
Joined
Feb 12, 2008
Messages
207
Yeah that's it, when this code is run I get a floating text on all the player's characters at the same time.

JASS:
function CheckLowHeat takes nothing returns nothing
 local integer i = 0

 loop
    exitwhen (i>10)
    if ( udg_Status_Heat[i] <= 20.00 ) then
      call FloatingTxt("Im cold", udg_Survivor[i], 55, 55, 100)
    else
    endif
    set i=i+1
 endloop
endfunction

function CheckLowHunger takes nothing returns nothing
 local integer i = 0
 local timer time = CreateTimer()

 loop
    exitwhen (i>10)
    if ( udg_Status_Hunger[i] <= 20.00 ) then
      call FloatingTxt("Im hungry", udg_Survivor[i], 70, 70, 0)
    endif
    set i=i+1
 endloop
 // Wait again and check the Heat
 call TimerStart(time, 10, false, function CheckLowHeat)
endfunction

function CheckLowEnergy takes nothing returns nothing
 // Check the Energy
 local integer i = 0
 local timer time = CreateTimer()

 loop
    exitwhen (i>10)
    if ( udg_Status_Energy[i] <= 20.00 ) then
       call FloatingTxt("Im tired", udg_Survivor[i], 15, 15, 100)
    endif
    set i=i+1
 endloop
 // Wait and check the Hunger
 call TimerStart(time, 10, false, function CheckLowHunger)
endfunction

//===========================================================================
function InitTrig_LowStats takes nothing returns nothing
    set gg_trg_LowStats = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_LowStats, 30.00 )
    call TriggerAddAction( gg_trg_LowStats, function CheckLowEnergy )
endfunction

What I would like, is that the messages show one apart from the other character if you get what I mean. Not at the same time. Like placing some waits inside the loops but thats exactly what I dont want to use, waits inside loops. Any ideas?
 
Level 6
Joined
Feb 12, 2008
Messages
207
nah, if u can see, the code shows up the message for all the units inside the array. I would want to make the units in the array to randomly show "im hungry" on one, then after a little "im cold" on another one, but what i dont want is having all the units matching the condition showing up i.e. "im cold" at the same time. just a little delay would be nice to make it look better.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
So the problem is that you don't want to use a "Wait" inside of a loop?

As Axarion said, you can use a hash-table to attach the necessary data to a timer and execute the timer on a periodic interval; each interval would increment an integer counter and then display the appropriate message for the appropriate unit, at the appropriate time.

"I need to mess up this code (really)" - this isn't a very accurate thread title.
 
Level 6
Joined
Feb 12, 2008
Messages
207
So the problem is that you don't want to use a "Wait" inside of a loop?
No, thats not the problem, but I saw somewhere in the forums ppl telling me about using waits inside loops, they mess up things but not in the way im wanting to do it.

As Axarion said, you can use a hash-table to attach the necessary data to a timer and execute the timer on a periodic interval; each interval would increment an integer counter and then display the appropriate message for the appropriate unit, at the appropriate time.
Yeah, never used hash-tables. I think Ill have to go and read some info about them. They look really powerful.

"I need to mess up this code (really)" - this isn't a very accurate thread title.
Yeah I think I should have used a more appropiate title for ppl with a problem similar to mine... sorry about that.
 
Status
Not open for further replies.
Top