Community

AGI Programming => Mega Tokyo AGI Archive => Topic started by: Xqzzy Rcxmcq on November 30, 2002, 04:14:26 PM

Title: Timers in AGI
Post by: Xqzzy Rcxmcq on November 30, 2002, 04:14:26 PM
This is a question!

How can you do timers in AGI? Does you do something with the clock? An example is the salesman clone launch countdown in SQ2.  ???
Title: Re:Timers in AGI
Post by: Patrick on November 30, 2002, 04:16:20 PM
timers as in actions preformed by the computer in an interpreter like have this stuff move and crap...or like a countdown timer?
Title: Re:Timers in AGI
Post by: Xqzzy Rcxmcq on November 30, 2002, 04:29:16 PM
I'm talking about countdown timers...I think I know how to move objects with timers already.
Title: Re:Timers in AGI
Post by: Patrick on November 30, 2002, 04:56:41 PM
ok then...sorry Nick, Chirs, and Joel know....
Title: Re:Timers in AGI
Post by: Xqzzy Rcxmcq on November 30, 2002, 05:04:20 PM
What I was thinking about was like for every increment for seconds, minutes, etc. for the game's internal clock, the timer counts down one second, minute, etc.
Title: Re:Timers in AGI
Post by: Kon-Tiki on November 30, 2002, 05:27:38 PM
If it doesn't have to count down from the clock (the one you get by pressing f6), it's this:
Code: [Select]
f(5) {
// rest of the starting code
v100 = x
}
if(v100 != 0) {
  v100 --
}
x is the number of seconds you want. This code can be a little buggy. That's because I can't remember the exact variable commands, but you still get the idea.

-Kon-Tiki-
Title: Re:Timers in AGI
Post by: Jelle on November 30, 2002, 06:00:21 PM
I would do like this:

Code: [Select]
if (f5) {   // f5 = new room, you can put any flag here
  v100 = x;
}

if (v100 == 1) {
  // do your stuff, for when timer ends (alarm), end of countdown... you know
}

v100--;

x is not the number of seconds, it's the number of logic cycles...
I use v100==1 and NOT v100==0 because if you would do that, everything in that block will be executed every cycle, until v100 is given another value...

The program will go like this:


* Enter room

* first cycle:
    set v100 the value x
    v100 = x-1

* second cycle
    v100 = x-2

* third cycle
    v100 = x-3
:
:
:

* x-1 th cycle
    v100 = 1
    special stuff will be done

* x th cycle
    v100 = 0

* x +1 th cycle
    v100 = 0

and so on...
Title: Re:Timers in AGI
Post by: Xqzzy Rcxmcq on November 30, 2002, 06:33:13 PM
Thanks, Kon-Tiki, thanks, Jelle. I'll have to keep that in mind. It was just kind of confusing. Oh, well. Thanks.
Title: Re:Timers in AGI
Post by: Andrew_Baker on December 01, 2002, 05:06:38 AM
I prefer:

If (new_room) {

    timer = 100;
     reset(timer_start);

}

if (timer_start) {
    if (timer == 0) {
        //Do whatever
    }
     else {
            timer--;
     }
}
Title: Re:Timers in AGI
Post by: Jelle on December 01, 2002, 08:32:45 AM
Didn't you forget anything? The if block will never be executed because you reset timer_start when the ego enters the room... ???
Title: Re:Timers in AGI
Post by: Andrew_Baker on December 01, 2002, 09:22:20 AM
Nah, the timer_start can be triggered by any event or command you want.

It could be

if (said("use","lever") {
    set(timer_start);
    }

or

if (has("widget")) {
   set(timer_start);
   }


One thing I should have added is reset(timer_start);  once the countdown is finished, to prevent an infinite loop.