Constant loop of If Statement that needs help

Started by , Sun 08/02/2004 23:04:36

Previous topic - Next topic

releasetehfrogs

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?

Kweepa

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);
}
}
Still waiting for Purity of the Surf II

releasetehfrogs

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.

Takara

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.

Darth Mandarb

#4
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?



rtf

#5
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"
I fail at art.

Gilbert

#6
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.

rtf

#7
ha ha, whoah

that was fast.  Robots are quick...

muchas gracias
I fail at art.

Kweepa

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);
}
}
Still waiting for Purity of the Surf II

rtf

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
I fail at art.

SMF spam blocked by CleanTalk