Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+3)

Now Serving,

The EggTimer Contraption

A countdown timer for a configurable number of seconds, firing a "finish[]" event and inverting in color when it completes. Clicking a second time resets the countdown.

%%WGT0{"w":[{"name":"eggtimer1","type":"contraption","size":[60,20],"pos":[226,161],"def":"eggtimer","widgets":{"b":{},"s":{},"a":{}}}],"d":{"eggtimer":{"name":"eggtimer","size":[60,20],"resizable":1,"margin":[5,5,5,5],"description":"a configurable countdown timer.","script":"on get_seconds do 0+s.text end\non set_seconds x do s.text:x end\n\non view do\n b.font:card.font\n if b.animated\n  e:(sys.ms-a.text)/1000\n  b.text:r:floor 0|get_seconds[]-e\n  if r=0\n   if b.show=\"solid\" card.event[\"finish\"] end\n   b.show:\"invert\"\n  end\n else\n  b.show:\"solid\"\n  b.text:s.text\n end\nend\n\non click do\n a.text:sys.ms\n b.animated:!b.animated\n view[]\nend","template":"on finish do\n \nend","attributes":{"name":["seconds"],"label":["Seconds"],"type":["number"]},"widgets":{"b":{"type":"button","size":[60,20],"pos":[0,0],"font":"body","text":"10"},"s":{"type":"field","size":[52,18],"pos":[4,-81],"locked":1,"style":"plain","value":"10"},"a":{"type":"field","size":[53,20],"pos":[3,-57],"locked":1,"style":"plain"}}}}}

hi there! if i replaced everything after:

"on finish"

with:

"go[card]"

would i be able to have a project that automatically jumps the viewer to a new card once the countdown reaches 0? thank you very much for this program by the way, it's great!

(+1)

Yes. Just to be clear, if you make an instance of the EggTimer contraption and edit it's script, it will have a template like

on finish do
end

You can then fill in an event handler for "finish" like you would any script. For example,

on finish do
 go["someCardName"]
end

Note that if the only thing you want to do is wait 10 seconds after clicking a button before navigating to another card you could use the sleep[] function on an ordinary button's script:

on click do
 sleep[10 * 60]
 go["someCardName"]
end

The difference being that sleep[] is "synchronous" and prevents the user from doing anything else while the script sleeps, whereas the EggTimer is "asynchronous" and the user could click something else or navigate away from the timer before it goes off.

ah, thank you for this. i'd rather use this asynchronous option because i aim to have the player click on elements of an image that either pop-up things or navigate to other cards while the countdown is still actively going on (not quite sure yet, but it's a work in progress).

I placed eggtimers on a bunch of cards, and then wanted to loop through them and change the Seconds value. I've done this in the Listener with Field widgets, but how do I do it with eggtimers? This doesn't seem to work, to change it for a single eggtimer:

eggtimer1.event["set_seconds" 180]
(1 edit) (+1)

The attribute exposed externally is `seconds`. The internal accessor/mutator functions are therefore named `get_seconds` and `set_seconds`, respectively. From the outside, you can modify the attribute like

eggtimer1.seconds:180
(+1)

Ah, it's shown under Prototype/Attributes...

I managed to look everywhere else.

Is there a way to automatically start the egg timer when a player goes to another page so there's no need for player intervention, but the page is still interactable? I tried calling eggtimer on click function on the onview function on a card it's currently at, but it doesn't seem to work. Would love the help thanks! 

(+1)

If you just want a timer and it doesn't need to be this "egg timer" specifically.... 

Making timers from scratch comes up from time to time, and it's pretty easy. 

Here's a small example in the programming questions thread that would start automatically when the card is viewed. 

And here's another thread talking about making timers.

If that seems like something that would work as a replacement for what you wanted the EggTimer Contraption for, then I'm very sure folks around here would be happy to answer questions to make sure your home made timer does what you want it to do.

(+2)

Oh my god you're a life saver thank you!