Skip to main content

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

Time-Out Function?

A topic by tinyfossil created 61 days ago Views: 242 Replies: 7
Viewing posts 1 to 3
(+2)

Hi ya'll!

I've been working on a game and wanted to see if anyone had any suggestions for a time-out feature! I've been trying to come up with a way to have my game send the player back to the first card if a certain amount of time has passed/they haven't moved their mouse after x minutes. I'm not amazing yet with coding widgets and had the thought to try and utilize the ".beat" widget or "pointer.pos" but I'm just not sure the best way to go about it.

Anything helps (also I've been loving Decker <3)! 

(+2)

So you can get the current time with sys.time, which is probably what you'll want to do to achieve this.

For an overall time limit you'll probably want to store the sys.time value in a hidden field somewhere in your deck when it starts, and then periodically compare it with the current time, maybe with an animated widget.

Not sure as much about the pointer, but checking whether pointer.pos has changed in combination with the above sorts of techniques could work.

It will probably need a bit of coding though. I know ahmwma's Tea And Bread uses the .beat widget to do some time tracking stuff so that could be an effective solution.

(+2)

Thanks, I'll check it out and try playing with that! (Also I follow your zine and I love it <3)

(+1)

Gosh thanks haha. Let me know if you have any luck / get stuck!

(1 edit) (+3)

On the subject of time... So, I did make Tea and Bread (as Millie mentioned -- thanks!) using the .beat clock for my timers. 

Specifically this version of it that sends out events and it does work for creating timers. It definitely does that.

But you can also skip the clock contraptions and make a simple text field or slider widget into a timer instead.


Using a text field as an example:
1. Make a field
2. Set it to be animated in the widgets menu (so that it experiences 60 'on view do' events per second)
3. Write a tiny script so that it increases the number inside the field every time there's a 'on view do' event:

on view do
me.text:me.text+1
end

Ta-dah! It's the basic building block of a timer.  This version of it will make the number go up forever.

But since we want to change cards when we hit a certain amount of time.... we can do something like this:

on view do
if me.text=300 # if the timer has reached 5 seconds (5 x 60 = 300) #
me.text:0 # reset the clock #
go[home] # and go to another card #
else
me.text:me.text+1
end
end

300 view events (5 seconds) is way too fast for what you're planning -- but I hope it's a nice understandable number for testing.

Any amount of time you want to use in your scripts should be converted into seconds, and then multiplied by 60 -- this is the total number of 'on view do' events that must happen before you reach your intended time.

----

Now, the bit I'm not sure about is the pointer -- I've never done anything with pointer.pos and I'm not sure how to script that off the top of my head (Sorry!)

But I will bring up the issue of mobile users, and offer an alternative (until someone more familiar with pointer comes along...)

It's a nice feature of Decker that the majority of decks work the same on touchscreen devices like phones and tablets as they do on computers.... but these devices don't track pointer.pos in the same way. They don't usually have a cursor to track the position of. (I think Decker just looks at the most recent tap on touchscreens...?)

It's possible that this is fine for your project and having it work slightly differently on mobile isn't a big deal. But, y'know, something to think about.

So here is a possible alternate version of your request -- one that resets the clock when there's a click/tap, rather than while the player is moving their mouse cursor:

on view do
if pointer.held # if a click happens #
me.text:0 # reset clock #
elseif me.text=300 #else, if we've reached 5 seconds on the clock....#
me.text:0  # reset the clock #
go[home] # and go to another card #
else
me.text:me.text+1 # make number go up#
end
end

And here's this version of the field widget to copy-paste into your deck if you'd like to mess with it :

%%WGT0{"w":[{"name":"field1","type":"field","size":[36,15],"pos":[228,35],"animated":1,"script":"on view do\nif pointer.held\nme.text:0\nelseif me.text=300\nme.text:0\ngo[home]\nelse\nme.text:me.text+1\nend\nend","show":"transparent","value":"0"}],"d":{}}

I hope this gives you something to work with!

And alternatively, if you wanted to use a slider instead of a text field for some reason: 
Use me.value in the script instead of me.text and make sure to set the maximum value of the slider to at least the number you intend for it to reach.

(+2)

Oh wow this is so helpful thank you so much! I knew there had to be a relatively straightforward way so now I feel a bit silly :')

I'll try both, and thank you for pointing out the issue with viewing on mobile, I hadn't thought of that! For right now I wanted to add this feature since I am working on having it run as a little installation, so I didn't want someone to come sit down and be in the middle of the game, and I didn't want to make a home button, so this is perfect.

I also just played through Tea and Bread and it was gorgeous. The animations were amazing and it's motivating me to do even more <3

Developer (1 edit) (+2)

Just adding to this, a few notes:

A field's .text property will always be a string. If you want to stuff non-string data into a field, like a number, list, or dictionary, and pull it back out as the same type you can use the .data property of the field instead. Either way is fine for simple applications.

With an auxiliary field (call it "lastpos") you can record pointer.pos and detect changes between frames (assuming the user didn't manage to precisely start and end on the same pixel within a 60th of a second). As Ahm noted, this approach is a bit brittle on touch-based devices, because they don't generally observe pointer movement except during clicks and drags:

on view do
 if !pointer.pos~lastpos.data
  me.data:0
 else
  me.data:me.data+1
 end
 lastpos.data:pointer.pos
 if me.data > 60*10
  me.data:0
  go[home]
 end
end

I'd recommend using pointer.down or pointer.up to detect clicks instead of pointer.held. If a user makes a very short tap (pressing and releasing within a 60th of a second), a script may not observe pointer.held as truthy. The pointer.down and pointer.up flags will be truthy if the pointer was depressed or released (respectively) at any time during the previous frame, and thus avoid the potential race condition. 

Does any of that make sense?

(+1)

Ahh I see! Using pointer.down definitely suits this particular case best after playing around, thank you so much!