How do I can set random number ?

Get help using Construct 2

Post » Thu Jun 30, 2016 7:52 am

I want to set a random number and when system choose a number after 24 hours system choose another one .

exp : cost for a flower : random( 18,25)
system choose : 21
after 24 hours system choose cost again.
Posts: 50
Reputation: 2,281

Post » Thu Jun 30, 2016 10:43 am

Message: signupdemo can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
You can do something like.... when system chooses the cost, save the cost and time/date on local storage,
and then compare the current time/date with the previously saved one.
If its less than 24hrs, display the saved cost, and if its more than 24hrs. choose new cost and then overwrite the local storage with the new data.

You can utilize RexRainbow's time plugin for it:
Last edited by signupdemo on Thu Jun 30, 2016 10:48 am, edited 1 time in total.
Posts: 76
Reputation: 739

Post » Thu Jun 30, 2016 10:45 am

You have this 'away' timer in place. It tells you how long the game has been offline.

It actual tells you also how long the game is running.

Just set a variable to round(TimeAwayL.ElapsedTime("away")), but this time only once and when it is zero (first start). The difference between the actual round(TimeAwayL.ElapsedTime("away")) and that variable = the online time.

Now the total time is just = TotalTime + that variabele (online time). TotalTime = zero for first run. The offline time (you have that one allready in place), we handle once on getting from the local storage.

You have to store total time in the local storage.

24 hours is 86400 seconds. (if i count right) So, its the same thing as you do allready with your build time.

So on TotalTime getting from the local storage.
TotalTime = TotalTime + away time (away time has to been get allready)
round(TotalTime /86400) gives you the amount of times this total time passed 24h.
If its bigger then 1 do the random thing
set TotalTime to (TotalTime) - (round((TotalTime /86400) * 86400), this sets the total time to the remaining second left to complete again a 24 hours cycle.

Say your total time is 216000... round(216000/86400) gives you 2 (2.5 rounded) ... means there are 2 times 24 h passed. Now there is still .5 times 24 hours left, and have to start from there for the new cycle. (TotalTime) - (round((TotalTime /86400) * 86400) gives you what is left.

Now the total time is just = TotalTime + that variabele (online time) again.

You do the same with buildtime, where you have to use ceil instead of round, because it is zero based.
Posts: 2,493
Reputation: 20,950

Return to How do I....?

Who is online

Users browsing this forum: luckyrawatlucky, R0J0hound and 24 guests