Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Sun 08/02/2004 23:04:36

Title: Constant loop of If Statement that needs help
Post by: on Sun 08/02/2004 23:04:36
Hello, everybody.

I have another problem.
I am running a script that makes it so that the player character says something if he dosent have inventory item 3:


function room_c() {
 // script for room: Walk off left screen edge
 while (player.inv[3] != 1){
   DisplaySpeech (1, "I can't go out there without protection.");
   }
}

As many people can see, the character will continue to say "I can't go out there without protection" for ever and ever.

Can someone tell me what I'm doing wrong?
Title: Re:Constant loop of If Statement that needs help
Post by: Kweepa on Sun 08/02/2004 23:27:25
The while will continually loop, giving the player no chance to get the protection.

Use if instead, like so:

function room_c() {
// script for room: Walk off left screen edge
if (player.inv[3] != 1){
DisplaySpeech (1, "I can't go out there without protection.");
}
else {
NewRoom(5);
}
}
Title: Re:Constant loop of If Statement that needs help
Post by: on Sun 08/02/2004 23:47:01
It still dosent work  :'(

I need to get it so work.

I dont know if there is a way to make him say "I can't go out there without protection" just once, rather than forever.

I can't find anything, because the "If not" kinda overrides the whole thing.

NITFM




If there was an award for the person who needs the most help, i would be a safe bet.
Title: Re:Constant loop of If Statement that needs help
Post by: Takara on Mon 09/02/2004 00:02:48
I think the problem is that your character is stood in the area marked "Now move to the new room", that's why you're getting stuck in a loop.

How about after the DisplaySpeech you use a MoveCharacter command to get the character back further into the current room?

Not tried it myself, so apologies if it doesn't work!

Takara.
Title: Re:Constant loop of If Statement that needs help
Post by: Darth Mandarb on Mon 09/02/2004 00:11:40
I put 2 regions (or hotspots when I did this) at that edge (wherever he can walk)

// When the player walks onto the outside hotspot
if (player.inv[3] != 1){ // doesn't have item
 DisplaySpeech (1, "I can't go out there without protection.");
 DisableHotspot(X); // whatever hotspot it is
 }
else {
 NewRoom(X);
 }

Then he can't walk off the screen and when he steps on the inner of the two Hotspots
EnableHotspot(X); // Turns the outter hotspot back on.

(Make sure the inner hotspot is positioned such that the player will have to trigger it when walking back from the edge.)

Does that make sense?


Title: Re:Constant loop of If Statement that needs help
Post by: rtf on Mon 09/02/2004 04:15:15
Awww, man.  It still dosent work.
Apperantly my character is big enough so that he is on the region, and off the region at the same time, so the "EnableRegion" overrides the "DisableRegion"
Title: Re:Constant loop of If Statement that needs help
Post by: Gilbert on Mon 09/02/2004 04:26:49
Do this:

Declare some tracking variable on top of that room's script, say:
int charsaid;

Then modify your walking off edge interaction script to:
function room_c() {
// script for room: Walk off left screen edge
while ((player.inv[3] != 1)&&(charsaid==0)){
DisplaySpeech (1, "I can't go out there without protection.");
charsaid=1;
}
}

Then if you want the char to say that again the next time he steps into the area, just add to repeated execute script:
if (character[1].x)>10) charsaid=0;

in above code I suppose the x coordinates of the left edge was set to 10, you can set it to any appropiate value if required.

EDIT: heh didn't notice the problem's solved, anywya, I'll leave this as reference.
Title: Re:Constant loop of If Statement that needs help
Post by: rtf on Mon 09/02/2004 04:36:36
ha ha, whoah

that was fast.  Robots are quick...

muchas gracias
Title: Re:Constant loop of If Statement that needs help
Post by: Kweepa on Mon 09/02/2004 09:07:20
Sorry about that earlier code.
This is what I normally do - walk the player character off the screen edge.

function room_c() {
// script for room: Walk off left screen edge
if (character[EGO].inv[3] != 1){
DisplaySpeech (EGO, "I can't go out there without protection.");
MoveCharacterBlocking(EGO, character[EGO].x + 16, character[EGO].y, 0);
}
else {
NewRoom(5);
}
}
Title: Re:Constant loop of If Statement that needs help
Post by: rtf on Wed 11/02/2004 03:29:16
Quote from: SteveMcCrea on Mon 09/02/2004 09:07:20
Sorry about that earlier code.
This is what I normally do - walk the player character off the screen edge.

function room_c() {
// script for room: Walk off left screen edge
if (character[EGO].inv[3] != 1){
DisplaySpeech (EGO, "I can't go out there without protection.");
MoveCharacterBlocking(EGO, character[EGO].x + 16, character[EGO].y, 0);
}
else {
NewRoom(5);
}
}


Ah ha!!! Perfect!  Snaps for Steve!!

Thanks