variables updating when game is closed

Get help using Construct 2

Post » Sun Jan 03, 2016 4:02 am

Hey everyone, just a general question here..

Lets say that every hour you want to add 1 to a variable but you want it to update even when the app is closed...

My logic would be ...

On app opened -> get date and time
On app closed -> store current date and time

On app opened -> Do math and work out how many hours have passed -> add to variable

Is this possible in construct ?

Thanks !
B
18
S
2
Posts: 48
Reputation: 896

Post » Sun Jan 03, 2016 4:35 am

yes it is possible. you would have to be able to save locally to add that feature. save on complete / quite layout - On start / load compare save status and adjust by time. before game resume.
B
29
S
13
G
10
Posts: 355
Reputation: 8,317

Post » Sun Jan 03, 2016 4:55 am

Carbincopy wrote:yes it is possible. you would have to be able to save locally to add that feature. save on complete / quite layout - On start / load compare save status and adjust by time. before game resume.


I tried using the "Browser.ExecJS("Date()")" but I am unable to get extract an actual value from it.
B
18
S
2
Posts: 48
Reputation: 896

Post » Sun Jan 03, 2016 8:29 pm

it would be time + 1 for every x sec of time = new variable it won't be able to be saved as a date/time variable in stead as a number. Just like a bonus timer in seconds.

So to set the variable it would be something like (d= +h= +m= +s= )= gamesaved
Thus gamesaved would look like

Updated: 03033600

and if they where to come back in 6 hours it would be
on load get value (d= +h= +m= +s= )= gameplay

Updated: 03063600

compare gamesaved with gameplay
for every x sec > then gamesaved = timeelapsed +1
set gameplay to gamesaved

if object is to move add timeelapsed to direction of move = new position of object.

Updated: The only issue I with the variable is that every day adds 76, every hour adds 40, minute adds 40. so you would need to adjust for that also.

I am pretty sure some one has created a .capx that does this exact feature you are looking for.
B
29
S
13
G
10
Posts: 355
Reputation: 8,317

Post » Tue Jan 05, 2016 1:06 am

@ryrydawg
This would give the current time in milliseconds:

Browser.ExecJS("Date.now()")

source:
https://developer.mozilla.org/en-US/doc ... jects/Date

You could also look here for a plugin that also does this:
viewtopic.php?f=153&t=63492

If nothing else you'll probably find an example that is helpful.
B
89
S
30
G
95
Posts: 5,157
Reputation: 63,450


Return to How do I....?

Who is online

Users browsing this forum: Darknessed, ismael123 and 10 guests