Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

HELP timer/countdows feature for cards?

A topic by Eenna created 5 days ago Views: 106 Replies: 6
Viewing posts 1 to 3
(+2)

Hi! In my game, I aim to have users click a button that switches them to a new card. This new card should only be displayed for three seconds before switching to a different card. In the meantime, I want the user to be able to interact and see the objects on this card. I've tried using sleep[] in the card's script but this blocks user input and makes Field (text) elements blurry until the sleep cycle is done. I have come across the eggtimer contraption (https://itch.io/post/7449415) and it seems very close to what I need to do (although on a click event), but I can't figure out how to adapt it and I've been trying for days. I would like the countdown to start as soon as the user navigates to the card and for the game to switch cards regardless of what the user may be doing. Does anyone have any advice?

(+3)

Hi! So a few things

  • The reason the field elements are made blurry when you're running sleep[] is because they're unlocked, so are greyed-out to indicate that they're not editable while sleep[] is running. For on-screen text that you don't want the user to be able to edit it's neatest to set the fields to "locked" (Widgets->Locked when they're highlighted), that way they won't grey out when input is locked, and users won't be able to mess with them.
  • In terms of adapting the eggtimer contraption, you'll likely need to edit the prototype of the contraption, if you go File->Prototypes you should be able to get to it. Probably what you'll want to do is change the "click" event into a function you can call externally, there's a bit about how to do this in the Custom Attributes section of the doco. Then you'd probably want to call this as part of the button that switches the user to a new card.
  • I would probably be inclined to roll my own code rather than using a contraption for this, to be honest. Probably I'd use a hidden slider set to "animated", which means it'll run its own "on view" function every frame. Then in the "on view" basically I'd have it increment its value by 1 each frame, and then check when it gets to greater than equal than 180 (i.e. 3*60) and go to the next card when it does. And the button to move to this card I'd set to reset the slider to 0.

Hopefully this makes sense - I'm not sure how experienced you are with programming (especially in Lil) but if you need some more help I might be able to give some code snippets when I'm more awake and able to check that they actually work and such.

(+4)

Hi Millie, thank you so much for your ideas! I especially tried implementing your third one (with the slider) and was  really close to getting it when ahmwma supplied the last piece I needed to make it work! Thank you so so much!

(+3)

Ahh, I'm glad you got a solution! I'm looking forward to seeing what you make!

(1 edit) (+3)

Following up on Millie's post -- I made a little slider example that does what she said in the last section. This slider is animated (60 view events per second), locked (not interactive for users in Interact mode) and volatile (doesn't save the value stored in it between sessions).

%%WGT0{"w":[{"name":"timerslider","type":"slider","size":[100,25],"pos":[152,105],"locked":1,"animated":1,"volatile":1,"script":"on change val do\n\nend\n\non view do\n if me.value=180 #60 frames per second x 3#\n me.value:0\n go[\"Next\"] #change this to the name of the card you want to go to#\n else\n me.value:me.value+1\n end\nend","interval":[0,180],"style":"compact"}],"d":{}}

And, explaining the script contained in it:

on view do
if me.value=180   
me.value:0   
go["Next"]   
else  
me.value:me.value+1  
end 
end 

Or, to explain it more casually:

on every view event (60 per second on this animated widget) 
IF my stored number has reached 3 seconds (180 = 60 frames x 3) 
reset me back to 0 
then go[] to another card 
ELSE (in any other circumstance) 
make my stored number go up by 1 
end (for the if statement) 
end (for the on view do)

Technically I made a "Count Up" rather than a "Count Down" but I hope it makes sense anyway! You're welcome to use or deconstruct this example for your project.

More notes:

Probably change the go["Next"] to have the name of the card you actually want it to go to?

A live countdown timer can be a little annoying while testing your other interactive elements... But it should be fine if the rest of the card is ready.

If it's annoying while testing anyway I can explain a way to make it easier to work around while editing your project. I wanted to keep it simple for this example.

When everything works how you like.... set this timerslider widget's visibility to "None" so your players can't see it. :)

(1 edit) (+3)

Hey ahmwma, I've been at this all day and was soooo close to getting it. haha. I actually arrived at most of the code snippet myself but to reset the counter, I tried doing it from the button on my previous card 🤦‍♀️. You gave me that last piece of the puzzle to make this work, thank you so much! And thank you for coding a widget I can use to speed up my process, it'll be so helpful! 

EDIT: in the copy-paste widget, I think you have me.value:me.value+1 there under both the if and the else?

(1 edit) (+2)

Oops, you're right! I changed my mind about how to do it while I was writing the post and I think I updated the widget in my open copy of decker and forgot to update the code snippet for you.

My mistake! I'll fix it for anyone who stumbles on the thread in the future. The codebox in the post is correct, and now so is the copied widget.

It sounds like you've got it figured out now, though. :D Good luck with your project!