How can I make an AI wait for a variable?

Post your scripting questions / solutions here

Moderator: Moderators

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

How can I make an AI wait for a variable?

Post by Krane »

After hours doing searches I decided to post this... :?

I have 2 AI targetnames "cit1" and "cit2". These 2 guys have a routine (go here, go there, wait, etc) and, at a certain point, they go towards a cardtable and start playing cards (btw, I'm not using the cardgame.scr).

When cit1 reaches the cardtable, I set a variable like this:

level.playcards[cit1] = 1

cit2 takes a random time to reach the destination, but always more time than cit1. When he reaches, I set:

level.playcards[cit2] = 1

Ok, I'd like to make cit1 sit and wait for cit2 for 30 sec. If cit2 arrives while cit1 is waiting, cit1 starts to play that animations etc, and go on w/ the thread...If not he leaves and go on with the thread...

This is what I have now for cit1 (Iwant him to react to the presence of cit2):

Code: Select all

routine_1:
level.playcards[cit1] = 0
wait 1
//MOVE AND SIT
self walkto $cardchair_1
self waittill movedone
self turnto $cardtable
wait 1
self anim chair_sit
self waittill animdone
iprintln "Citizen 1 is in the cardtable!"
level.playcards[cit10] = 1

//THIS IS THE CRAPPY PART, DON'T LAUGH!!! :lol: 

self anim chair_actor1_idleloop //WAITING
self waittill animdone //AT THIS POINT HE LEAVES
if(level.playcards[cit2] == 1)
{
iprintln "cit 1 detected cit 2"
self anim chair_actor2_idleloop //MAIN LOOP
self waittill animdone
self anim chair_actor1_fish
self waittill animdone
self anim chair_actor2_drawcard //GRAB A CARD
self waittill animdone
self anim chair_actor1_queen //GIVE ME THE QUEEN
self waittill animdone
}
self anim chair_curious_stand //BOTH SITUATIONS SHOULD LEAD TO HERE
self waittill animdone
goto routine_10

end
I know why is not working! I just dunno how to make it work... :? I've try "while" "if" etc...But the truth is that I'm not good w/ scripts...(took me an hour to understand the difference between "=" and "==") :oops:

Can somebody clarify this cloudy brain? :shock:

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

boo boo

Post by tltrude »

Well, I see one error:

level.playcards[cit10] = 1

Shouldn't that be "cit1"?
Last edited by tltrude on Wed Feb 18, 2004 2:09 am, edited 2 times in total.
Tom Trude,

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

Post by Krane »

Thanks, tltrude. I' already fixed that.

And yes, I'm setting "level.playcards[cit1] = 0" in the beggining of the routine, so when they reach the playcards point, they set "level.playcards[cit1] = 1"

The same for cit2! When he reaches the playcards point, he sets "level.playcards[cit2] = 1"
Last edited by Krane on Wed Feb 18, 2004 2:10 am, edited 1 time in total.
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

print

Post by tltrude »

Has "level.playcards[cit2] = 1" been set before hand in another routine? You can use this line to find out for sure:

iprintln "level.playcards[cit2] = " + (level.playcards[cit2])
Tom Trude,

Image
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

don't use waittill animdone for both players, they need anims to be playing until the shorter anim is played and then new anims are set

i've remade the script, and you should be able to use it, this is part of the script that spawns everything, self is the table, $player1 is self.player[1] and $player2 is self.player[2],
so...


rountine_1:
if (self.player[2].playing == 1) //player 2 is playing :D
{self.player[1] anim ("Chair_actor1_idleloop")
self.player[2] anim ("Chair_actor2_idleloop")
self.player[1] waittill animdone
self.player[1] anim ("Chair_actor1_queen")
self.player[2] anim ("Chair_actor2_idleloop")
self.player[1] waittill animdone
self.player[1] anim ("Chair_actor2_idleloop")
self.player[2] anim ("Chair_actor2_fish")
self.player[2] waittill animdone
self.player[1] anim ("Chair_actor1_drawcard")
self.player[2] anim ("Chair_actor1_idleloop")
self.player[1] waittill animdone
self.player[1] anim ("Chair_actor1_idleloop")
self.player[2] anim ("Chair_actor2_king")
self.player[2] waittill animdone
self.player[1] anim ("Chair_actor1_fish")
self.player[2] anim ("Chair_actor2_idleloop")
self.player[1] waittill animdone
self.player[1] anim ("Chair_actor1_idleloop")
self.player[2] anim ("Chair_actor2_drawcard")
self.player[2] waittill animdone}
self.player[1] anim ("Chair_curious_stand") //after the "if" is complete this will be used
self.player[1] waittill animdone
goto routine_10
hope this helps, prob not cos it's all foreign 2 me :-/
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Great idea Tom! :D . Simple and cool!

Thanks nuggets, but I'm affraid that these routines must be separated from each other, as other bots will use them...After hours I figure out a way, not the solution, but a way to make it:

Code: Select all

routine_1:
level.busychair[chair1] = 0
level.playcards[cit1] = 0
wait 1
self walkto $smoking_2
self waittill movedone

//--LIGHT UP A CIGARRETTE--//
self anim smoking01
self waittill animdone
self anim smoking02
self waittill animdone
wait 1

//CLUNCKING AROUND
self anim chatter03
self waittill animdone
wait 1
self anim smoking02
self waittill animdone
wait 1

//GO PLAY CARDS-CHAIR 1
if(level.busychair[chair1] == 0)
{
self walkto $playcards_1
self waittill movedone
self turnto $cardtable
wait 0.5
$cardchair_1 thread movechair1
self anim chair_sit
self waittill animdone
level.playcards[cit1] = 1
level.busychair[chair1] = 1
iprintln "Citizen 1 is in the cardtable!"
}

//GOOD LUCK!
if(level.playcards[cit2] == 0)
waitthread waitcardsloop

if(level.playcards[cit2] == 1)
{
self waitthread playagame_1
}
self anim chair_curious_stand // STAND UP
self waittill animdone
level.playcards[cit1] = 0
level.busychair[chair1] = 0
iprintln "Citizen 1 is done with beting!"

self anim smoking04
self waittill animdone

goto routine_1

end




//===========ROUTINE 2=========//
routine_2:
level.busychair[chair2] = 0
level.playcards[cit2] = 0
wait 1
self walkto $lit_cigarette_1
self waittill movedone

//--LIGHT UP A CIGARRETTE--//
self anim smoking01
self waittill animdone
self anim smoking02
self waittill animdone
wait 1

//GO PLAY CARDS
if(level.busychair[chair2] == 0)
{
self walkto $playcards_2
self waittill movedone
self turnto $cardtable
wait 0.5
$cardchair_2 thread movechair2
self anim chair_sit
self waittill animdone
level.playcards[cit2] = 1
level.busychair[chair2] = 1
iprintln "Citizen 2 is in the cardtable!"
}

//GOOD LUCK!
if(level.playcards[cit1] == 0)
waitthread waitcardsloop

if(level.playcards[cit1] == 1)
{
self waitthread playagame_2
}
self anim chair_curious_stand // STAND UP
self waittill animdone
level.playcards[cit2] = 0
level.busychair[chair2] = 0
iprintln "Citizen 2 is done with beting!"

self anim smoking04
self waittill animdone

goto routine_2

end


//WAITING ANIMATION

waitcardsloop:
self anim chair_waiting_idleloop_nocards
self waittill animdone
self anim chair_waiting_idleloop_nocards
self waittill animdone
self anim chair_radio_listenidle
wait 3
self anim chair_waiting_idleloop_nocards
self waittill animdone
end



//--------------PLAYTYPES--------------//

//1ST PLAYTYPE - NEEDS MORE ANIMS
playagame_1:
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor1_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_fish // COMMENT GO FISH
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor2_king	// GIVE ME YOUR KING
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor1_drawcard // YOU ALWAYS CHEAT
self waittill animdone

end

//2ND PLAYTYPE - NEEDS MORE ANIMS
playagame_2:
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor1_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_fish // COMMENT GO FISH
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor1_queen // GIVE ME YOUR QUEEN
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor1_fish // COMMENT GO FISH
self waittill animdone

end
Now cit1 play an loop thread while wait for cit2...The problem is that HE DON'T INTERRUPT THIS LOOP THREAD WHEN CIT2 ARRIVES...but that's ok, this is the far I can get hehe...Is thgere a way to interrupt that thread and tell him to go on w/ the thread?

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

Post by jv_map »

See the nearby topic about ending threads by small_sumo ;)
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Thanks jv, helped a lot :D !

Now I have this:

routine_1:

level.busychair[chair1] = 0
level.playcards[cit1] = 0
wait 1

if(level.busychair[chair1] == 0)
{
iprintln "Citizen 1 is going to play cards."
waitthread playcards_1
}

self anim smoking04
self waittill animdone

goto routine_1

end


and

routine_2:
level.busychair[chair2] = 0
level.playcards[cit2] = 0
wait 1

if(level.busychair[chair2] == 0)
{
iprintln "Citizen 2 is going to play cards."
waitthread playcards_2
}

goto routine_2

end


The playcards

playcards_1:
self walkto $playcards_1
self waittill movedone
self turnto $cardtable
wait 0.5
$cardchair_1 thread movechair1
self anim chair_sit
self waittill animdone
level.playcards[cit1] = 1
level.busychair[chair1] = 1

if(level.playcards[cit2] == 0)
self waitthread waitcardsloop

if(level.playcards[cit2] == 1)
{
iprintln "Citizen 1 is in the game!"
self waitthread playagame_1
}
self anim chair_curious_stand // STAND UP
self waittill animdone
level.playcards[cit1] = 0
level.busychair[chair1] = 0
iprintln "Citizen 1 is done with beting!"

end


playcards_2:
self walkto $playcards_2
self waittill movedone
self turnto $cardtable
wait 0.5
$cardchair_2 thread movechair2
self anim chair_sit
self waittill animdone
level.playcards[cit2] = 1
level.busychair[chair2] = 1

if(level.playcards[cit1] == 0)
self waitthread waitcardsloop

if(level.playcards[cit1] == 1)
{
iprintln "Citizen 2 is in the game!"
self waitthread playagame_2
}
self anim chair_curious_stand // STAND UP
self waittill animdone
level.playcards[cit2] = 0
level.busychair[chair2] = 0
iprintln "Citizen 2 is done with beting!"

end


The waiting thread!!!

waitcardsloop:

while (level.playcards[cit2] == 0)
{
self anim chair_waiting_idleloop_nocards
self waittill animdone
}

end


Everything is fine, when cit2 arrives, cit1 starts the playcard animation, etc...except that cit1 is waiting endlessly for cit2...He will stay forever there and I wanted him to wait for 15 sec and then leave...

Anyway, WOW, what a big improuvement from the first crap, thanks guys!!! :D :D :D
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

counter

Post by tltrude »

What you need is a timer. They are not too hard to make and you can find them in a lot of script using the variable names "level.waittime" or "local.wait".
Tom Trude,

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

Post by Krane »

Do such thing exists? :shock: WOW, sound exactly what I need! :D Thanks tltrude, I'll do a search! 8-)
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Little question:

while (blabla = 1) && (blublu > 15)
{
whatever
} end

&& means AND, right?

What means OR ??????? :roll: :roll:

And another one:

After shooting my beloved citizens and after their bodies dissapear, the chairs starts a crazy ballet going front and back (probably coz the thread went to a loop or so..). Question:

Is it ok to "envolve" the whole thread in a:

while (isAlive)
{
the thread here!
}

:?:

Thanks :D
Last edited by Krane on Fri Feb 20, 2004 8:07 am, edited 1 time in total.
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Post by tltrude »

I don't know about the chair, but here is the "or".

while ((blabla == 1) || (blublu > 15))
{
whatever
}
end


Notice the double brackets. All of the expresions are in MOHAATools/docs/ScriptFiles.txt under "precedence".
Tom Trude,

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

Post by Krane »

Thanks, my General! :D

Will take a look as soon as the sun shines!!! :shock:
Image
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

your thread needs a break

waitcardsloop:

while (level.playcards[cit2] == 0)
{
self anim chair_waiting_idleloop_nocards
self waittill animdone
break
}

end
hope this helps, prob not cos it's all foreign 2 me :-/
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Waiting animation

Post by Krane »

Breaking the thread will make the bot to finish that thread and this suppose to be a loop thread...Actualy, I'm very confused :? ...The "while" statement suppose to check for the condition every time (dunno.. :roll: )...Actualy, I'm uderstanding that "if" check for that condition one time and make the choice, no look behind 8-) "while", for instance, suppose to ALWAYS check for the condition, right?

I discovered that doing this example:

In a certain moment, cit3 ( it's a third guy) do this:
if((level.busychair[chair2] == 1) && (isalive self))
{
self turnto $lightpost1_aim
wait 1
waitthread lightpost1
}
self anim atease
self waittill animdone
end
That means that, while chair2 is occuppied, cit3 will play the lightpost thread, if not play an atease anim. Now the lightpost thread:
lightpost1:

while (level.busychair[chair2] != 0)
{
self anim scientist_wallchart_depressed_sci2
wait 1
}
end
A very simple loop! :) It's working!! :D If I kill cit2, cit3 stops the animation and goes on with the thread! :D (probably coz the thread reaches the "}" every 1 sec. and THEN check the condition again... :shock: )

Well,now cit1: He have a very similar part as cit3:
if((level.playcards[cit2] == 1) && (isalive self))
{
iprintln "Citizen 1 is in the game!"
self waitthread playtype_1
}
level.playcards[cit1] = 0
level.busychair[chair1] = 0
self anim chair_curious_stand // STAND UP
self waittill animdone
iprintln "Citizen 1 runs out of money!"
If chair1 is available (and he's alive of course), he will playcards! But now, the difference!!! Check my playtype thread:
playtype_1:

while((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_king // GIVE ME YOUR KING
self waittill animdone
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor1_fish // COMMENT GO FISH
self waittill animdone
self anim chair_actor1_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_king // GIVE ME YOUR KING
self waittill animdone
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
self anim chair_actor1_idleloop // MAIN LOOP
self waittill animdone
self anim chair_actor1_drawcard // YOU ALWAYS CHEAT
self waittill animdone
}

end
If I join as a player and shoot cit2 in the head ( :oops: ), cit3 stops imediatly his animation and goes on w/ his life ( cool!)...but cit1 insists on keep playing cards w/ that dead body on the floor. :? ...gr... :x ( probably coz the thread will reach the "}" ONLY AFTER doing the whole animations! :? )

So I did this monster:
playtype_1:

if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_king // GIVE ME YOUR KING
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor1_fish // COMMENT GO FISH
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor1_idleloop // MAIN LOOP
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_king // GIVE ME YOUR KING
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_idleloop // MAIN LOOP
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor2_drawcard // PICK UP A CARD
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor1_idleloop // MAIN LOOP
self waittill animdone
}
if((level.busychair[chair2] == 1) && (isalive self))
{
self anim chair_actor1_drawcard // YOU ALWAYS CHEAT
self waittill animdone
}

end
That was the only way out of the problem! I must say, it's working, but it's funny how "while" do not check if the chair was available or not...Once it started the sequence of animations, it was going on 'til the end...

Anyway, the big problem: the waiting animation! :x I'm using a thread as a counter :
counter_15min:
iprintln "Timeout Started!"
wait 15
level.timeout = 1
iprintln "Time is over!"

end
Very crappy, I know :oops: , but works! 8-)

And the d*** waiting thread ( cit1):
waitcardsloop1: // I had to add the #1 to the label
//level.timeout = 0
thread counter_15min // starts the counter
while ((level.timeout != 1) || (level.busychair[chair2] != 1)) //d*** line
{
self anim chair_waiting_idleloop_nocards
self waittill animdone
}

end
I Tryed:

while (level.timeout != 1 || level.busychair[chair2] != 1)
while ((level.timeout == 0) || (level.busychair[chair2] == 0))
while (level.timeout == 0 || level.busychair[chair2] == 0)

and other options I can't remember now :? :? Don't work!! :cry:

But when I try only one of the conditions, it work! Like:

while (level.busychair[chair2] !=1)
while (level.timeout == 0)

Both works!!! :shock: So my timer system works and the busy chair check works also... "||" is indeed OR...There's another "bitwise or" which is "|"...tryed and nothing... buaaaa...:cry:

What am I doing wrong :? :?:
Image
Post Reply