SetTimer in 'repeatedly execute' - solved

Started by leone, Sat 17/07/2004 11:44:39

Previous topic - Next topic

leone

Ã,  Hi guys,

Ã,  I started making a game with AGS a while ago and I find it great fun. But I came across a big problem. I started working on an arcade room in which the player would guide a boat up a river, and a crocodile was supposed to appear and swim down the screen.
Ã,  So I used the script I found in the ‘Arcade Driving room' of the Demo Game, and put this in my room script for the crocodile character:

Ã,  // script for room: Repeatedly execute

if (IsTimerExpired(1)) { // croc

character[CROC].x = 180;
character[CROC].y = 94;

Ã,  croc = Random (2);
Ã,  if (croc==0) {
Ã,  MoveCharacterDirect (CROC,81,260);
Ã,  }
Ã,  else if (croc==1) {
Ã,  MoveCharacterDirect (CROC,81,260);
Ã,  }
Ã,  else if (croc==2) {
Ã,  MoveCharacterDirect (CROC,101,260);
Ã,  }

Ã,  timer1 = Random (3);
Ã,  if (timer1==0) {
Ã,  SetTimer (1,230);
Ã,  }
Ã,  else if (timer1==1) {
Ã,  SetTimer (1,230);
Ã,  }
Ã,  else if (timer1==2) {
Ã,  SetTimer (1,270);
Ã,  }
Ã,  else if (timer1==3) {
Ã,  SetTimer (1,300);
Ã,  }

}

But the thing simply won't work. I think that the problem is with the SetTimer function, which doesn't work in ‘Repeatedly execute' part of the script. The program seems to be working too fast for the function to be performed. It seems that SetTimer works only when I put it in ‘before fadein' part of the script.
Ã,  How can I make SetTimer work in ‘Repeatedly execute'?
Ã,  Is there any other routine I can use to make the croc appear at different intervals?
Mister No is coming

Barbarian

Ummm, not quite sure, but at the first of your script where you have

"if (IsTimerExpired(1))"

Ã,  It might need to be changed to:

"If (IsTimerExpired(1)==1)"

Ã,  Ã,  Someone with more scripting experience may give you better advice though.
Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

leone.

Yes, I tried that, didn't work.
I also tried to change the number of the timer.

By the way, in the 'before fadein' bit, I have this

ChangeCharacterView (MISTERNO, 9) // main character
SetCharacterIdle (MISTERNO,10,0);
DisableCursorMode(0);
character[MISTERNO].x = 160;
character[MISTERNO].y = 199;
SetGameSpeed(40);

But I don't see the problem there.
In the global script I just put a script in the on_key_press section for left and right arrows.

What bugs me is that the same script works in the Demo Game.

Barbarian

That's strange then if you say it works in the demo but not in your game.
It might be something "obvious" being overlooked?

Just a thought, but is the "CROC" character in fact in the same room with your character with that script being run? So, for example, let's say all this is happening in room 10, then to insure the CROC character is in the correct room, you might add in the "before fadein" a command such as:

character[CROC].room = 10;

Ã,  Ã,  Other than than, you might try to verify if your script is indeed being run properly at all by tempoarily putting in some "Display" commands, such as:

"character[CROC].x = 180;
character[CROC].y = 94;
Display("Test message 1");"


Ã,  Ã, etc.. for the different parts of the script and that way you can sort of "debug" if a part of a script is being run or not.

Ã,  Ã, Well, that's about all the advice I think I can offer for now. I think someone else on the forums will probably soon give you some better advice.Ã,  ;)Ã,  Good luck.



Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

davey

you need to put an initial SetTimer in Player Enters Room, otherwise it will never expire for the first time and never run the code

leone

  That's it, there's my crocodile! Thanks Davey!
  And thank you Barbarian for trying to help. I'll use your advice for checking for bugs with Display function in the future.
Mister No is coming

SMF spam blocked by CleanTalk