Author Topic: A global countdown initiated at a user specified time  (Read 3199 times)

0 Members and 1 Guest are viewing this topic.

Offline MusicallyInspired

A global countdown initiated at a user specified time
« on: August 27, 2011, 06:58:05 PM »
I'm sure eventually I could figure this out, but since I'm short on my time lately I was wondering if anyone had any ideas to go about doing this. It's probably even fairly simple but I haven't scripted SCI in a long time and right now I have a headache lol.

I'm working on a short demo project where the player is fine initially, but when he encounters a certain event a global timer starts. This timer counts down globally no matter where the character is in the game across any screen. And when the timer reaches zero he dies. But if he beats the game the countdown is cancelled. Any and all help would be appreciated. Thank you.


Brass Lantern Prop Competition

Offline gumby

Re: A global countdown initiated at a user specified time
« Reply #1 on: August 28, 2011, 06:58:30 PM »
Putting something in the Main.sc would work - perhaps in the handleEvent method?  I would think that it would be handled the same way that other global things would be handled (time of day, score, etc).  Hope it helps.

Dammit.  I need to get back into my SCI projects as well.  :(
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline MusicallyInspired

Re: A global countdown initiated at a user specified time
« Reply #2 on: August 28, 2011, 09:12:34 PM »
Yeah, I figured it'd go in Main. But I'm trying to figure out how exactly to wrote the code to make it countdown. It's easy enough to make a variable and throw a line of code in the doit method. I assume I'd manipulate that variable with how the engine calculates time with the clock and everything but I'm just not sure how at this point.
Brass Lantern Prop Competition

Offline lskovlun

Re: A global countdown initiated at a user specified time
« Reply #3 on: August 29, 2011, 02:15:28 PM »
Is http://sciprogramming.com/community/index.php/topic,83.0.html useful, by chance?
I have a few additions to that original how-to, which I am going to post there.

Offline MusicallyInspired

Re: A global countdown initiated at a user specified time
« Reply #4 on: August 29, 2011, 02:21:51 PM »
I was just reading that tutorial again today and remembered it. If I understand correctly, it's possible via regions? If you throw it in the region will that keep running in the background even if you switch from room to room as long as they are part of the same region? I'm looking forward to the additional how-to information.
Brass Lantern Prop Competition

Offline MusicallyInspired

Re: A global countdown initiated at a user specified time
« Reply #5 on: September 19, 2011, 06:12:52 PM »
I've just tried implementing this in my region. I set a countdown for 7 seconds in the region's 1 changestate case (case 1, not case 0 so that it doesn't start right away) which then warns about the halfway mark, then for another 7 seconds which triggers another message and the death event at case 2. I didn't use a Timer I just set the region's changestate to trigger via its doit method upon the incrementing of a global variable to "1", after which is increments it again to "2" so that it doesn't keep happening.

It works fine.....as long as you stay in one room. Unfortunately, the region's script is reset along with everything else when you go into a new room, even if that room also uses the same region. My only other recourse is to just program it into the Main script instead and do it globally.

EDIT: Well, I'm not sure how to implement this globally in the Main script as it doesn't have a changestate method and when I try to add it, a ton of errors come up about not knowing what "state" is etc. I'm really at a loss on how to implement a global timer.
« Last Edit: September 19, 2011, 06:16:11 PM by MusicallyInspired »
Brass Lantern Prop Competition

Offline Cloudee1

Re: A global countdown initiated at a user specified time
« Reply #6 on: September 20, 2011, 11:29:28 AM »
How about setting the number and counting down in the main script. then in the region script use a doit method to trigger a changestate method which is also in the region script... if countDown = 7 do state 1... Then again, if countDown = 1  do state 2
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline MusicallyInspired

Re: A global countdown initiated at a user specified time
« Reply #7 on: September 20, 2011, 02:03:30 PM »
How to decrement the global variable, though? If I just throw it in the doit method in Main it'll countdown insanely fast. I'm sure I could utilize the in-game clock somehow in this way but I don't have any ideas.
Brass Lantern Prop Competition

Offline MusicallyInspired

Re: A global countdown initiated at a user specified time
« Reply #8 on: September 20, 2011, 03:49:05 PM »
I've got something going here, but as I feared the variable is decremented waaaay too fast to be usable. I've just got to figure out a way to only decrement the variable when the gTimeSeconds variable is updated rather than every game cycle.
Brass Lantern Prop Competition

Offline Cloudee1

Re: A global countdown initiated at a user specified time
« Reply #9 on: September 20, 2011, 07:27:20 PM »
Specifically seconds then... How about this: in main create two variables. one to decide if the timer is actually keeping time and the other to keep track of what time it is when the timer started. So assuming the player has a bit before the countdown begins start off with keepTime = false and timeStarted= 0... now whenever the event is triggered, keepTime becomes true and timeStarted=gtimeseconds or whatever it's called, judging from your post about time in the menu bar, I assume you know the global variable I'm talking about. Now, in the region scripts doit method  set up the condition so that 1st check that keepTime is true. 2nd check  the global seconds value - the timeStarted value.  if it equals x trigger state 1 of the regions changestate method, else if it equals y then trigger state 2. Minor issues will be that you will have to change the global seconds value as soon as it triggers true  or every cycle that ticks by during that second will trigger state 1 or state 2, so just add 1 to it.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline MusicallyInspired

Re: A global countdown initiated at a user specified time
« Reply #10 on: September 21, 2011, 02:11:44 AM »
Actually, what I ended up doing was adding a timer variable with a certain value (in seconds. actually I probably could have made it in minutes instead...would have made more sense lol) and, similar to what you described, if a second variable is assigned TRUE, the time keeping script in Main (the (if(<> gCurrentTime (= gCurrentTime GetTime(gtTIME_OF_DAY))) part) begins to decrement the former variable each time gTimeSeconds is updated. So it happens perfectly in time with the game clock. Next I used the region script to check whether the timer variable reaches certain numbers and if it does, to change the region's state to specific numbers which have different effects (ie- halfway through, when the countdown reaches 0, etc). It works well, but your way probably makes more sense and is much more clean to base it on the game clock precisely with the difference of how much time is passed instead.
« Last Edit: September 21, 2011, 02:19:10 AM by MusicallyInspired »
Brass Lantern Prop Competition

Offline Cloudee1

Re: A global countdown initiated at a user specified time
« Reply #11 on: September 21, 2011, 12:19:47 PM »
Whatever works. I don't know if my way is cleaner though. Basing it just off the gseconds like I described wouldn't quite get you theree. you would have had to convert the hours and minutes times back into seconds to test correctly (or introduce a total seconds variable) otherwise you would have run into trouble when the seconds reset from 60 to 0
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


SMF 2.0.14 | SMF © 2017, Simple Machines
Simple Audio Video Embedder

Page created in 0.121 seconds with 23 queries.