Andrew_Baker | Awright, I checked the help files to no avail. How do I set a timer in AGI? I just need a few seconds of zombies wandering around for a mini-game (Three Zombie Monte). Then, they'll go to preset positions and stuff. Anyway, I need a timer. |
sonneveld |
Usually you set aside a variable, set it to zero initially, which you then add one to for every game loop (at the end of your room logic perhaps). Then, when it reaches a certain value, you do something like start or stop an animation. If you want timers that last for longer than 255 game loops, you can try having two variables, with one you increase when the other reaches it's limit. but then you have to check the value of two variables when you check for a certain time. // two var example if (newroom) { timer1_a = 0; timer1_b = 0; set(timer_started); } if (timer1_b == 0 && timer1_a=50) { // start animation } if (something happens) { // it's also possible to speed things along too. // (say all the puzzles have been done so you don't need // the extra time for your player timer1_b = 2; timer1_a = 0; } if (timer1_b == 2 && timer1_a=20) { // print msg, stop animation // don't need timer anymore. reset(timer_started); } if (timer_started) { if (timer1_a == 255) { timer1_a = 0; timer1_b++; } // agi does not allow incrementation to overflow. // so, unchecked, timer1_a could just stay at 255. timer1_a++; } else { // set it to 0 here or at the end of your series of things // (when you reset timer_started timer1_a = 0; timer1_b =0; } um.. I hope that helps. It's used in a lot of places. Police Quest uses it at the start to see if you miss the first meeting or not. V uses it for it's intro sequence. And I'm pretty sure lots of other games use it too. - Nick |
Andrew_Baker | Oh, I should have guessed. For some reason, I thought AGI might have a native timer. Thanks. |
Andrew_Baker |
Yep, thanks, Nick. It works just fine, now. |
MagickPoultry | Is there no way to use the clock-time? I thought they did that in King's Quest 3. |
sonneveld |
I haven't looked into kq3's timer code but I would have thought it would be a bit trickier since you would be playing with four variables then.. seconds, minutes, hours, days and you'd probably have to do a bit more arithmetic to figure out if you've reached a current time.. I'll have a look. Using the repeating cycles to count down is nice because if the player decides to walk around on a faster speed, you can make sure they have less time to do things. - Nick |
sonneveld |
I had a quick look and I think the timer code is in logic.106 (there's lots of wizzah code..) I don't see any mention of using the clock vars.. but I'm probably not looking in the right place. I tried playing the game at fastest speed and they do manage to show the wizard for the correct times.. no matter what speed it's set to. - Nick |