Can't stop a looping script [SOLVED]

Started by markcullinane, Mon 31/01/2005 15:08:35

Previous topic - Next topic

markcullinane

Hi,
I have an object appearing on screen, which is gradually fading in using the SetObjectTransparency function.
Using ClaimEvent and if keycode 32 (i.e spacebar) is pressed down, then the object should disappear and the game continues. (the script below should make some sense at least)

However, there is a problem. As the script is in repeatedly_execute, it keeps looping and control is lost over the character in the game. To prevent this, I tried setting GlobalInt(1) to 1 when the object appears, and when it disappears, it changes GlobalInt(1) to 2. I'm trying to use a while statement to only run the long piece of script when GlobalInt is set to one, so essentially the whole thing only runs once.

I know it's a convoluted way of doing it, but can anybody fix the mistakes in the script? Any help would be very much appreciated.

Thanks.

(In room script's repeatedly_execute)


while (GetGlobalInt(1) == 1) {
  // code here
function on_key_press(int keycode) {
  // called when a key is pressed. keycode holds the key's ASCII code
 
if (keycode==32) SetObjectTransparency(2,0); Wait(3);
SetObjectTransparency(2,0); Wait(3);
SetObjectTransparency(2,5); Wait(3);
SetObjectTransparency(2,10); Wait(3);
SetObjectTransparency(2,15); Wait(3);
SetObjectTransparency(2,20); Wait(3);
SetObjectTransparency(2,25); Wait(3);
SetObjectTransparency(2,30); Wait(3);
SetObjectTransparency(2,35); Wait(3);
SetObjectTransparency(2,40); Wait(3);
SetObjectTransparency(2,45); Wait(3);
SetObjectTransparency(2,50); Wait(3);
SetObjectTransparency(2,55); Wait(3);
SetObjectTransparency(2,60); Wait(3);
SetObjectTransparency(2,65); Wait(3);
SetObjectTransparency(2,70); Wait(3);
SetObjectTransparency(2,75); Wait(3);
SetObjectTransparency(2,80); Wait(3);
SetObjectTransparency(2,85); Wait(3);
SetObjectTransparency(2,90); Wait(3);
SetObjectTransparency(2,95); Wait(3);
SetObjectTransparency(2,100); Wait(3); 
ObjectOff(2);
ClaimEvent(); SetGlobalInt(1,2);


Scorpiorus

#1
Put the following code within room script:

int object_transparency = 0;
int speed = 1;
function on_key_press(int keycode) {

Ã,  Ã,  if ((keycode == 32) && (object_transparency == 0))
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  while (object_transparency <= 100)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetObjectTransparency(2, object_transparency);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Wait(1);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  object_transparency = object_transparency + speed;
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  object_transparency = 100;
Ã,  Ã,  Ã,  Ã,  SetObjectTransparency(2, object_transparency);

Ã,  Ã,  Ã,  Ã,  ObjectOff(2); // optional
Ã,  Ã,  Ã,  Ã,  ClaimEvent();
Ã,  Ã,  }

}

markcullinane

That code you suggested doesn't seem to be working, Scorpiorus . I replaced what I had before with your new one, and it hasn't solved the problem at all- in fact it has no effect on the game. Character movement (along with everything else) is still blocked because parts of the script continue to loop.
Any other ideas?

Scorpiorus

#3
Can you post your room script?

EDIT: Ah, there is a mistake I made sorry, look above I changed the code a bit.

markcullinane

That new script works like a dream!
Thanks again Scorpiorus, you're brilliant!
Problem solved.

TerranRich

For all future reference, instead of doing the same command over and over again with incrementing numbers, a "while" command helps a LOT. This goes for anybody starting off that happens to read this. :)
Status: Trying to come up with some ideas...

SMF spam blocked by CleanTalk