Page 1 of 1

waitthread

Posted: Fri Sep 02, 2005 3:50 am
by lizardkid
For a script of mine i need to know when a certain few AI have finished their little duties from a list of cute AI tricks i'm maknig them do, i made a thread that has a while loop checking to see if they've all had their .done fields set to 1, if so it moves on and finishes. since i'm calling it as a waitthread, it should hold at that thread until the htread terminates before moving, right?

for some reason it isn't doing that. it overflows my script, after putting in some debug lines i found it was indeed an infinite loop...

the relevant part of the waitthread

Code: Select all

waitToSquadDone local.squadNum:

//^ 
// code i knows works, that gets the local.GSquad array.

while(local.GSquad[1].done == 0 && local.GSquad[2].done == 0 && local.GSquad[3].done == 0 && local.GSquad[4].done == 0 && local.GSquad[5].done == 0 && local.GSquad[6].done == 0)
{
	wait 1
}
for(local.z = 7; local.z > 1; local.z--)
{
	if(local.GSquad[local.z].targetname != NOT)
	{
		local.GSquad[local.z].done = 0 // reset their .done
	}
}

println "Squad " local.squadNum " has finished it's task."
end
i'm stumped. by all appearances that thread shouldn't end til all their .done's are set (which i've checked and rechecked, that isnt set until they're finished).

is there a different way of calling a thread i need to do instead of waitthread?

the reason i'm not posting more code is because it's such an interconnected script it'd be difficult for you to follow anyway.

hmmm

Posted: Fri Sep 02, 2005 4:22 am
by tltrude
Well, I don't get how it works to good, but shouldn't you have a variable for the numbers?

while(local.GSquad[local.squadNum].done == 0)

You could also use.

while(local.GSquad[local.squadNum].done != 1)

Here is a simple way to check if things are done.

Code: Select all

allies_win_bomb local.bomb1 local.bomb2:

	while (local.bomb1.exploded != 1)
		wait .1
	while (local.bomb2.exploded != 1)
		wait .1

	teamwin allies
end

Posted: Fri Sep 02, 2005 6:28 am
by jv_map
Even though your code is somewhat weird (especially the for-loop going backwards from 7 to 2 :?) there's nothing in there that could cause an infinite loop. Hence the error is somewhere else. Perhaps the thread is called in a loop with no other waits? Then it gets pretty obvious the error is not resetting #1's .done value to 0 in combination with a logic error in the while condition. Your loop doesn't end when all squad m8s have their .done on 1 but when any has. You could fix it by replacing all the &&s with ||s, but the construct tltrude showed is much nicer, and easily expandable for arrays of generic size.

Code: Select all

for(local.i = 1; local.i <= $whateverarray.size; local.i++)
{
  while !($whateverarray[local.i].done)
  {
    waitframe // or wait 1.0 if you have more patience than me
  }
  $whateverarray[local.i].done = 0 // reset right here
}

Posted: Fri Sep 02, 2005 1:29 pm
by lizardkid
Oh... i see it now DOH!
I'm ashamed, that was so obvious :(

thanks guys :oops: