How can I keep variables changing when game is suspended/offline?

From the Asset Store
five golem elements Sprites Sheet.Best for enemy or villain game characters.
  • Let me clarify the problem:

    - I'm building a weather system that interfers in many aspects of the game.

    - The game is based on real-life elapsed time, for example: my character in the game is crafting a item that will take 10 real-life hours to finish, and the weather during this 10 hours will interfer in the item quality when it finishes.

    - The weather has a chance to change every hour IN THE GAME.

    - So, if I stay offline in this 10 hours, I need to know if it was 5 hours sunny and 5 were cloudy to determine the item quality. But since I capture a Timestamp when the game is suspended and another one when it's resumed, I just get the elapsed offline time, but not the weather changes.

    How can I keep this variables (the weather to keep changing and saving the elapsed time in each weather condition) changing offline?

    Thank you so much for reading this and helping me out! :)

  • I'm not sure if its possible.. if its suspended, its suspended..

    You probably need to compare and simulate it on every resume for example..

    On resumed, get the amount of time suspended..

    Lets say 3 hours.. ok, so 3 hours means 3 weather changes, so for each hour, random (sunny, cloudy) and simulate the result of these hours suspended.

  • You should avoid background work at all costs - it will kill the battery life.

    I don't see why you can't just look at the timestamp when waking up, see 10 hours have passed, and then do the same thing as if 10 hours had just passed. For example if every hour you pick a random weather type, when the app wakes up after 10 hours, pick a random weather type 10 times.

  • First of all, thanks for the replies! :)

    I agree with you guys, but it will be a little weird to do like you guys said. I'll explain why:

    If I suspend the game while its Sunny, there is no chance that will be Snowy in the next hour, it's like a cycle, and every weather change has a probability to happe. For example: If it's sunny now, there is 50% chance that will remain Sunny, 40% chance that will be partly cloudy in the next hour and 10% that it will be windy. See the image below:

    So let's say that the player went 10 hours offline and then came back to the game... I need to calculate the probability based in this cycle for every hour. Do you guys have any suggestion on how to do that? Nothing comes in my mind when I think about it..

    Other ideia that may work here, is creating an online server/site/whatever and make a global weather for each city in the game, so I can "upload" from this repository the last 10 hours weather condition. What do you guys think? Is this possible? Or the other idea is more effective?

    Thank you so much!!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Whatever you do when an hour has gone by, just do it repeatedly when the app resumes, depending on how many hours went by. A "Repeat" loop should do the trick.

  • First of all, thanks for the replies! :)

    I agree with you guys, but it will be a little weird to do like you guys said. I'll explain why:

    If I suspend the game while its Sunny, there is no chance that will be Snowy in the next hour, it's like a cycle, and every weather change has a probability to happe. For example: If it's sunny now, there is 50% chance that will remain Sunny, 40% chance that will be partly cloudy in the next hour and 10% that it will be windy. See the image below:

    So let's say that the player went 10 hours offline and then came back to the game... I need to calculate the probability based in this cycle for every hour. Do you guys have any suggestion on how to do that? Nothing comes in my mind when I think about it..

    Other ideia that may work here, is creating an online server/site/whatever and make a global weather for each city in the game, so I can "upload" from this repository the last 10 hours weather condition. What do you guys think? Is this possible? Or the other idea is more effective?

    Thank you so much!!

    Hiho,

    your image is not showing..

    But, let me suggest to you:

    Variables:

    Weather, On_Suspended_Time, On_Resumed_Time, Suspended_Time.

    Create a function, "On_Resumed_Simulate"

    This functions will run every on resumed.

    On suspended:

    1 - Store the time to the var On_Suspended_Time;

    On resumed:

    1 - Store the current time to the var On_Resumed_Time;

    2 - Do the math between On_Suspended_Time and On_Resumed_Time to know hours or minutes that the game was suspended and store it to the var Suspended_Time;

    3 - Call On_Resumed_Simulate(Suspended_Time);

    Function On_Resumed_Time:

    1 - Receive the amount of hours suspended;

    2 - For each hours suspended

    2.1 - Compare var Weather = Sunny

    2.1.1 - Choose (Rainy, Cloudy) (If you need probability chance of pick, you can use here advanced random, Like 40% of Rainy, 60% Cloudy)

    2.1.2 - Do whatever you need after the change of weather, like if it will be on normal, running game..

    2.2 - Compare var Weather = Rainy

    2.2.1 - Choose (Sunny, Cloudy, Snowy) (If you need probability chance of pick, you can use here advanced random, Like 20% of Sunny, 60% Cloudy, 20% Snowy)

    2.2.2 - Do whatever you need after the change of weather, like if it will be on normal, running game..

    Im not sure if its clear to understand, but you need to do all the steps every On Resumed on "On_Resumed_Simulate"

    Ashley; why the forum does not respect the normal break lines?

  • It worked, guys!!!

    Thank you so much!!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)