Skip to main content

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

Creating a global timer

A topic by Ryan Kubik created 2 days ago Views: 57 Replies: 2
Viewing posts 1 to 3
(2 edits) (+1)

I want to have a global timer going in my deck that can detect if the player has done a given action within the last 5 minutes. If they have done that action, I want to reset my timer.

timer with animated widget

I’ve figured out I can create a timer by animating a widget and setting its value on view, with a script like this:

on view do
 me.text: me.text + 1
 
 #if me.text = 3600
 # my_event[]
 #end
end

I think I can use my_event later to trigger my time out behavior. I think I could reset the timer’s current value to reset the countdown fine.

My current issue is that I want this timer to be tracking time globally and not just on a single card. From what I can tell, my timer widget is only animated if it is on the current card.

Is there a reasonable way to get a timer this?

trying to copy paste timer widget

The current thing I’m trying to do is figure out how to copy/paste the widget across views cribbing some notes from this topic: https://itch.io/t/3658580/moving-widgets-between-cards-while-interacting-with-deck

I’m having trouble adapting it to my case though. I don’t seem to see go being triggered on my deck level script. I’m not seeing view being triggered consistently on my deck level script either.

I’m not seeing the go!!! print in my listener ever and am only seeing the current card print on one of the cards in my deck and not the rest.

on go dest trans delay do
 print["go!!!"]
 print[dest trans delay]
 send go[dest trans delay]
end
on view do 
 print["current card:", deck.card.name]
end
(+1)

Ah, I think that the on view do was not triggering because when you open a Card that does not have a script, then it gets populated with a template empty view event. This event was catching the view event and then it never made it up to my Deck view script.

Developer(+1)

I think that intercepting go[] and migrating a timer between cards as the user moves through the deck sounds a bit brittle.

Perhaps the technique described here would be helpful:

https://itch.io/t/5630988/shared-state-and-singleton-widgets

You could place an instance of such a contraption- with an internal animated widget- on every card where time is meant to be passing.