clock expire

Get help using Construct 2

Post » Wed May 22, 2013 2:38 pm

how do I make it so an item expires after 1 hour whether or not the app is open--or if its been 1 hour it expires when the open it back up
B
39
S
10
G
7
Posts: 514
Reputation: 9,426

Post » Wed May 22, 2013 3:00 pm

Make an plugin, choose a given one or use on that let you execute JS-Code. There are many.

If you make your own plugin or use a JS-Code-Plugin:

new Date().getTime(); Will return the actual milliseconds since year 0 save this for your item.

As soon as the player starts the game again you just check with new Date().getTime(); if the new value is an hour bigger than the old ;)
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Wed May 22, 2013 3:15 pm

You'd need some way of syncing real-world time with a source outside of the game. There are 2 plugins that get the system date an time on the user's computer:

Clock
System Date and Time

If you're concerned that the user would cheat by messing with their system clock, you can sync with an external source to get the correct time, but this is a bit more complex. If you have your own server, you can get the time by setting up a simple PHP script. Then, within the game, ajax request the php page.

Once you have a method of getting the current time, all you'd need to do is record the time the item is acquired, and destroy the item if more than an hour or more has passed.
B
44
S
13
G
7
Posts: 338
Reputation: 10,389


Return to How do I....?

Who is online

Users browsing this forum: selaus and 0 guests