How can I make an AI wait for a variable?

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

time

Post by tltrude »

Your counter_15min thread only waits 15 seconds.

counter_15min:
iprintln "Timeout Started!"
wait 900 // = 15 minutes
level.timeout = 1
iprintln "Time is over!"

end
Tom Trude,

Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Yeah, I know...Just mispelled the s***...I want it to wait for 15 sec... :oops:

But The labels are equal in both threads :D
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

test

Post by tltrude »

You can do a tempory test to see if the two conditions are true. This thread will contiously print the values to the screen (every second).

temp_test:

while (1)
{
iprintln "timeout: " (level.timeout)
iprintln "busy chair2: " (level.busychair[chair2])
wait 1
}

end


I think you'll find that they are not 0 or 1.

-------------------------------------------

Btw, using the double bracket is the right way.
while ((level.timeout == 0) || (level.busychair[chair2] == 0))

In the conditions above, the variable values must already have been set to 0 or they will not be true. In other words, a variable does not have the value of 0 automattically, it has the value of NIL until the value is set to a number. Normally these values are set in prespawn, if it will be used a lot. But, you can set them anywhere they will be read before the while line starts checking.

level.timeout = 0
level.busychair[chair2] = 0

You can also set them like this.

if (level.timeout == NIL)
{
level.timeout = 0
}

But normally that is used to see if the value has been set by another script. So, if it were set to 1 already it would not change it. Anyway, as you can see, NIL can be used as "no value".

-------------------------------------------

For all those if statement, You might look into using "for". I'm not real good at using it though. But, I think "for" is also a contiously checking loop.

Hope that helps!!!
Tom Trude,

Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Eureka!

Post by Krane »

Your temp test is pretty cool, thanks my General :D !
And the double brackets are definitly right 8-) !

I can see everythinhg is changing fine...Actualy I solved this d*** annoying problem...Here's the new waitthread:
waitcardsloop1:
thread counter_15sec
while !((level.timeout == 1) || (level.busychair[chair2] == 1))
{
self anim chair_waiting_idleloop_nocards
//self waittill animdone
wait 1
}
level.timeout = 0
level.busychair[chair1] = 0
iprintln "A place is available at the card table"
end
Notice the "!" after the "while" :wink: FINALLY IT'S SOLVED!!!!

Thanks guys, without you m8s I'd never make it!

And I learned my lesson :wink: !
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Now it's 3 variables...

Post by Krane »

hmm, I was about to start a new post but...it's related!

I want the bot to wait for 3 variables this time. So, can I do this:

while !((level.talk[talk1] == 0) || (isalive self !=1) || (level.token1e2 == 1))
{
etc
}
end

If 1 of these 3 conditions are met, then end the thread. Is this working?

Thanks!
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

I will not even try to say whether that would work or not, but what I can say is that it looks a little expedient.

Try this:

Code: Select all

while (level.talk[talk1] == 0 && isalive self && level.token1e2 == 1) 
:)
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

I have already tryed that jv and, for some reason, didn't work :cry: ! The only way is to deny first (while ! ). Without the "!", I had no success...

I did a very crazy test to simulate the 2 first conditions and, finally, test if the bots were reacting to the 3rd condition. And yeah, it works :D !

How many "&&" and/or "||" can we have?

Who knows what waits for me later... :shock:

Thanks m8!
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

!

Post by tltrude »

The "!" symbol means "is not". So, if you put it right after the while, it will run the loop while everything in the bracket is not true. But, when one of the things in the bracket becomes true, the looping will stop.
Tom Trude,

Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Yes sir 8-) ! I realize that! The funny is that jv's method is, of course, far simple and suppose to work...Was one of my first trys...but, for some reason is not, maybe when I tryed that, I had a mistake somewhere...Well, It's working anyway! :D
Image
Post Reply