Zinc 'while loop' issue

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
I left out the part that calls this function, but basically it was working when I just had

JASS:
'KillUnit(player1);'

'player1' / 'player2' etc are global units declared in another script

But when I added this part

JASS:
while (RectContainsUnit(GetEntireMapRect(), player1) == false ) {
 
        TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 1));
   KillUnit(player1);
   }
   }

It no longer kills the player and I believe is just waiting endlessly.
I'm trying to wait until this unit enters the map and when it does run the rest of the trigger klling the unit. What am I doing wrong here? Thanks. Full function below.



JASS:
function onLeaveHuman() {
    player p = GetTriggerPlayer();
    integer pid = GetPlayerId(p);
    Bases.playerUnclaim(p);
 
   if (GetTriggerPlayer() == Player(1)) {
 
        while (RectContainsUnit(GetEntireMapRect(), player1) == false ) {
 
        TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 1));
   KillUnit(player1);
   }
   }
   else if (GetTriggerPlayer() == Player(2)) {
   while (RectContainsUnit(GetEntireMapRect(), player2) == false ) {
        TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 1));
   KillUnit(player2);
   }
   }

 
 
}
 
Level 12
Joined
Dec 2, 2016
Messages
733
Okay, I did this. Haven't tested yet but this should work right? And if it works or appears to work, is it an okay way of going about it?


JASS:
boolean confirm;
function returnHuman() {
if ( RectContainsUnit(GetEntireMapRect(), player1) == false ) {
confirm = false;
}
else confirm = true;
KillUnit(player1);
}


JASS:
function onLeaveHuman() {
if (GetTriggerPlayer() == Player(1)) {
   returnHuman();
        while (confirm == false) {
   returnHuman();
   }
   }
}
 
Level 12
Joined
Dec 2, 2016
Messages
733
Can you explain what you changed and for what purpose? And before asking you should test.

I created another function that checks the map for the unit and if it's found sets the confirm boolean to true. And the while loop waits until the boolean is true. I thought what you said was I needed to call it from another function?

And yeah sorry I'm not home atm just on phone didn't get a chance to test.
 
Well what I meant is you need to use a timer to call a function periodically instead of using the TriggerSleepAction to make time-gaps between the checks.
If needed, data can be attached to a running timer via hashtable. You might check out JASS Class if you want to practice in this regard.

And yeah sorry I'm not home atm just on phone didn't get a chance to test.
But it feels like "I am too lazy to test". In many threads I'm not very sure you carefully read what people say, and keep asking things that were clarified already, or could be easily tested. Sorry, just a feeling.
 
Level 12
Joined
Dec 2, 2016
Messages
733
But it feels like "I am too lazy to test". In many threads I'm not very sure you carefully read what people say, and keep asking things that were clarified already, or could be easily tested. Sorry, just a feeling.

I work full time, as well as stream long hours after work. I only save an hour or two each day for map development. I am not to lazy to test, testing takes time and if I can reduce that time by asking questions here while I'm at work that saves me time in just running into more errors when I get home. And I do read all these threads, I am still learning, this is only a hobby for me and I may not understand all that is said but I am trying to retain everything mentioned.
 
This isn't specified to here but, but me personally, if I see someone isn't putting effort himself, then I will think twice next time before investing time for help.

Like from first solution-attempt, I don't see relation to what I suggested. But you suppose me/us to explain things again, without having anything tested.
It's like assuming others should use their time instead of you testing simple and replicateable things. It's totally ok if you only want to use x-time for coding yourself, this has not much to do with that.

But cheers, that was enough blabbering, I hope you can fix the trigger
 
Level 12
Joined
Dec 2, 2016
Messages
733
So this is what I came up with, it still doesn't seem to kill the player or perhaps it's not running the function. Would you be able to tell me what I did wrong here?

JASS:
function killPlayer() {
timer t=GetExpiredTimer();
if (GetTriggerPlayer() == Player(1) && RectContainsUnit(GetEntireMapRect(), player1) == true) {
KillUnit(player1);
PauseTimer(t);
DestroyTimer(t);
}
}
JASS:
function onLeaveHuman() {
    timer t=CreateTimer();
    TimerStart(t, 1.00, true, function killPlayer);
        t=null;
}
 
GetTriggerPlayer() can only be used in Trigger actions/conditions, not in other function calls or trigger callbacks.
So when starting the timer, data needs to be binded to the timer to have still access to it, later.

For example, when starting the timer, the respective unit (by player1/2...) can be binded to the timer by using hashtable, and timer's handle id as key.
When timer periodically expires you can load this data again to make check of unit is inside world.

Btw, maybe ..
  • heroes can be assigned into a global unit array? so unit[0] will be unit by player red, unit[1] by player blue, etc? Then unit[GetPlayerId(...)] might be used to refer to the correct units
  • would maybe a new trigger with "A unit enters world region" be an alternative solution, without periodic checks?
 
Status
Not open for further replies.
Top