Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(+1)

as someone who procrastinates a lot, i'm building a timer in decker using a field and a button to both act as a focus tool and also to apply some newfound programming knowledge. i have the basic countdown, but i'm wondering how i can make the program delay a second before going through the while loop again. any help is appreciated!

on click do  
    while display.text>0   
        display.text: display.text - 1  
        #delay goes here   
    end 
end
(+1)

You could use the sleep[] function to wait a given number of frames. "sleep[60]" would delay for approximately one second.

A different approach for timing (which could be more accurate over longer time periods) would be to use `sys.now` or `sys.ms` to record a starting time and then consult them periodically to determine how much time has passed, possibly using "sleep[]" to delay between checks. (See: the System interface)

(+1)

Thank you to the both of you! This helps a lot.

(3 edits) (+2)

sleep[] looks a bit unsatisfying, as the card is not interactive as it waits, so the label isn’t that readable.

I have tried this:

Make a textfield to store a timer (here I used “timer”) initially set to 0. You can put it on another card if you want to hide it out the way.

Card:

on view do
 timer.text:timer.text+1
 if (timer.text<0) & ((10%timer.text)=0)
   display.text:display.text - 1 
 end
 go[card]
end

Button:

on click do
 timer.text:(display.text+1)*-10
end

Edit: I was late to the party. Using sys.now as suggested above sounds like a more suitable approach :)

Using the same "view[] refreshing" strategy is definitely the best way to do something like this if you want to be able to interact with the rest of the card while the timer is running.

You can also make the "secret timer" field invisible if you want to hide it on the current card.

https://cptnqusr.itch.io/super-cool-timer

here's the finished timer! not exactly the greatest thing ever but as a first project i'm quite happy with it