Timed event, making a phone ring?

Started by Sayhello-hello, Fri 02/04/2010 18:08:08

Previous topic - Next topic

Sayhello-hello

Hi,

I'm trying to set up some sort up function that has the effect of a phone ringing, so that a message ("ring ring") will pop up at a certain time interval until you've picked up a phone.
So far this is what I have, which I realise isn't much, but I didn't really know what to do. :-\

 function ring() {
  if (Ending == true) {
    SetTimer(1, GetGameSpeed() *10);
      }
 if (IsTimerExpired(1)) {
        cHello.Say("Ring... Ring...");
        ring();
}
  }

barefoot

#1
Set the Timer to run as required.

Example:

Code: ags

SetTimer(1, 280); 


Remember 40=1 second. Example is set to run after 7 seconds.

You then need to put 'Is Timer Expired' in the Rep Execute Events panel for it to REPEAT after every loop.

Code: ags

if (IsTimerExpired(1)){
 cHello.Say("Ring... Ring...");

SetTimer(1, 280) 


Will reset Timer 1 to loop after cHello Says Ring Ring, untill player does something to stop the loop like pick up the phone, change view, clicks a certain object, area etc etc
You could also include a PlaySound() of a Telephone ringing..

Code: ags

if (player.HasInventory(ibook))
{
  SetTimer(1, 0); 


Will stop Timer1 If player has a certain inventory, like ibook example. But you can set your own condition like if player changes view, clicks a certain object, area etc etc
 
Amend code as is required. This is a basic start.

Others will be able to help you some more..

barefoot

I May Not Be Perfect but I Have A Big Heart ..

Crimson Wizard

#2
barefoot, I don't understand why you felt a need to explain all that, since Sayhello-hello already seem to know how to set timer.

Sayhello-hello, Practically, you've did almost everything.
What is important, is where in the code to place the timer-setting and checking.


Put "ring" function call into particular event handler, depending on when you need it to start ringing.

It is better to check Timer inside room's repeatable_execute function. This will ensure it will be checked each game tick.

When character takes the phone, call SetTimer(1,0) to stop the timer.

If you have more problems, please tell in detail which are you having, for at this moment I can't guess what to explain. You seem to know anything you need already.

barefoot

QuoteSo far this is what I have, which I realise isn't much, but I didn't really know what to do.

barefoot
I May Not Be Perfect but I Have A Big Heart ..

Crimson Wizard

Oh  :P

Well, okay.
This is actually why I wrote that I can't guess what to explain :)

Sayhello-hello

Well, thanks for the help.

I modified the code to this, but nothing happens when I call the function. I tried just making it say "ring ring" when I call function, and that works. I think the problem might have something to do with the fact that this has to run in all rooms until the player finds the telephone. So far this function is in the global.asc, and is only called from one room (not the room where the telephone is).

Crimson Wizard Are you suggesting that I check the timer inside every room? Sorry if it's a dumb question, but my brain can't quite get to grips on how to execute this.

Thanks for the help, again. :)

Code: ags
 function ring() {
  if (Ending == true) {
    SetTimer(1, 200);
      }
 if (IsTimerExpired(1)) {
        cHello.Say("Ring... Ring...");
        SetTimer(1, 200);
}
  }

tzachs

Firstly, if you want the phone to ring no matter what room you're in, you have to check the timer expired in the reapeatedly execute in the global script, not in the rooms.

Other than that, if you call the ring function you have in the repeatedly execute and the "Ending" variable remains true, than you are setting the timer again on every game loop which might explain while nothing happens to you. In that case, you probably want to call the first set timer only once, by doing something like:
Code: ags

function ring() {
  if (Ending == true) {
    Ending = false;
    SetTimer(1, 200);
      }
  if (IsTimerExpired(1)) {
        cHello.Say("Ring... Ring...");
        SetTimer(1, 200);
  }
}

This will set the Ending to false after the first time and so the timer will only be set once (and each time it expires).
If you need the Ending variable for some other stuff, you can do this instead:
Code: ags

function ring() {
  if (Ending == true && Game.DoOnceOnly("FirstTimeRingTelephone")) {
    SetTimer(1, 200);
      }
  if (IsTimerExpired(1)) {
        cHello.Say("Ring... Ring...");
        SetTimer(1, 200);
  }
}

Sayhello-hello

It works! ;D The problem was that I hadn't found the repeatedly_execute(), which seems like a silly thing to overlook in hindsight, but there you go.

Thanks for helping me out!

SMF spam blocked by CleanTalk