SkipTimer function?

Started by Gepard, Mon 05/01/2009 21:53:28

Previous topic - Next topic

Gepard

I have a function called Loading and this function only animates a gui button and than Wait for 4000 loops (out of 28000 in the Timer 1). For example if player clicks on a button called "rest" this function "Loading" will start. The thing is, that I dont want the player to wait that long. I want the game to skip this amount of loops so the player doesnt have to click or press any key as you do with Start and End Cutscene. Is it possible?
Drink up me 'arties! Yo ho!

Khris

#1
I've read the last sentence four times now and still have only a vague idea about what you want to achieve.
You want to code an equivalent to Wait(4000); that allows the player to skip to the end of the 100 seconds of wait time, right?

Code: ags
bool IsAnyKeyPressed() {
  bool yes;
  int i=32;
  while(i<200) {
    if (IsKeyPressed(i)) yes = true;
    i++;
  }
  return yes;
}

bool WaitSkip(int loops) {
  bool skipped;
  int i;
  while(i<loops) {
    if (IsButtonDown(eMouseLeft) || IsButtonDown(eMouseRight) || IsAnyKeyPressed()) skipped = true;
    i++;
    Wait(1);
  }
  return skipped;
}


EDIT:
I've read your post again.
Do you want Timer 1 to expire 4000 loops earlier?

Gepard

Just imagine a dark room. The timer is ticking from 28800 to zero. Player has only this limited time to do something about the game. If he decides to rest, than 4000 out of 28800 will elapse immediately after he clicks on the button "rest" so basically yes, I want the timer to expire 4000 loops earlier. I know i can put a code like this.

if //he presses the button "rest" {
startcutscene
gui.animate
wait 4000
endcutscene
}

but this requires a player to click or press a key to end the cutscene. i want to do the same without him to click or press a key. So is your code good for this? So far its the most complex one I was about to use in my game  ;D
Drink up me 'arties! Yo ho!

Khris

#3
This can't be done with an AGS timer, you have to use your own:

room script:
Code: ags
// top of room script
int timer;
bool timer_running;

function on_call(int p) {
  if (p == 1) timer -= 4000;
}

// instead of SetTimer(1, 28800);
  timer = 28800;
  timer_running = true;

// inside room's rep_ex, instead of ->    if (IsTimerExpired(1)) { ... }
  if (timer_running) {
    timer--;
    if (timer < 0) {
      timer_running = false;
      ...  // whatever is supposed to happen if the timer expires
    }
  }


global script:
Code: ags
// button is pressed
  CallRoomScript(1);   // this calls on_call(1) in the room script, advancing the timer by 4000


Edit: SkipTimer(int timer, int loops); might make a reasonable feature to include in the next release?

Gepard

Yeah, you are right, that would be a very nice function. Im trying to work with the code that you wrote for me, but Im afraid, Im just a beginner. Can the SkipTimer function be created or not? That would make my life much easier, but I dont think thats possible...
Drink up me 'arties! Yo ho!

Khris

I've put comments in the code (lines starting with "//") that tell you exactly where to put the pieces.

Since you've been working with a timer, you must have SetTimer(...) and if (IsTimerExpired(...)) already inside your room script, right?
Replace those parts with the code I gave you, put the first lines at the top of the room script, outside any function, then put the very last line in the button's OnClick function.

It's not a big deal to write a Timer module that includes a SkipTimer function; until then, my code should work fine.

What doesn't work? Do you get any error messages?

SMF spam blocked by CleanTalk