Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

offline code

Discussion in 'Scripting' started by megatron0, Feb 8, 2019.

  1. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    hi, is there a way to make a line of code works when the game not open?
    like i want to enable a button when time=5pm
    i already got the time from a server
    so if the player opened the game at 5:30 he finds the button enabled
     
  2. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    206
    "hi, is there a way to make a line of code works when the game not open?"
    I don't know that, but if what you want is :
    " if the player opened the game at 5:30 he finds the button enabled"
    Then you just need to check time in a Start() function to enable or not the button ?
     
  3. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    but by the time the player will open the game it is 30 minutes later than the code 5pm will it still work?
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    @Thibault-Potier covered it.

    Well, you have to set up your conditions. What determines that the button appears? Just 5pm or after? What determines that it isn't there? You said if the player opens at 5:30 the button is there. If you only want the button to appear if they are in the game at 5pm, then you'll have to check time, probably using a timer or something.

    What you want to happen isn't really clear.
     
  5. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    sorry couldnot explain better ,
    its a sign in button that appears when a new day comes which is 5pm for example if he opened 5:30 then the new day came and he can sign in
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Still not certain what you want exactly. But if the app opens, you check the time. If it's 5pm - 11:59 pm, display the button? If it's not, there is no button?

    Not sure about the new day part, do they only get to sign in after they have the game for 24 hours?
     
  7. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    no its a daily sign in like any othergame
    the button appears at the start of the day
    and can be clicked anytime but "start of the day is 00:00" so if he wasnot on at that time the code wont work while i want to to work and for the button to be enabled
     
    Last edited: Feb 8, 2019
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Well, for the games we make, you don't have to sign in daily...even the ones I play don't normally have a daily sign in. Unless you're talking about the daily reward?

    Anyways, you have to figure out what you want to define that the button should appear. Does the user have to be in your game at a certain time? Do they just need to open your game during a certain time frame? If I sign in once, then does my sign in expire, then do I just have to sign in the next time I log in after a certain time?

    I am having trouble following what you actually want because I'm seeing conflicting descriptions.

    So you just need to consider that you are not running code when the game is closed. Which means you need to consider what happens when the player opens your game and you can grab the time at that moment.
     
  9. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    How about you post a link to the game you're obviously inspired by? Would save a lot of time.
     
    lordofduct likes this.
  10. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    yes daily reward but to get it u click a button
    and yeah my case is the 2nd part
    i already have the time and everything but as u said the code which makes the button appear everyday wont work unless its 12:00 and if the player not online at that time he should have the button appear when he opens the game for the first time in the day
     
  11. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    final summoners war of heroes
    mobile game sadly it shutdown months ago but i can relate to daily rewards of summoners war/pubg or any other game
     
  12. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Ok, so with daily rewards, you should just check the day. Normally, I suggest a backend service to record when they last logged in. Basically, player logs in for the first time. You check, they have no recorded time. You offer them the daily reward and then record a timestamp.

    Next time they log in, you check that recorded timestamp. If it's a new day, offer them the daily reward. If not, no daily reward. Best to just record the timestamp on a server and not locally where they can clear it.

    You can also look into something on the asset store like
    https://assetstore.unity.com/packages/tools/integration/daily-rewards-free-110798
     
  13. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    thanks i understand it now , one last question how to detect that its a new day? is there a specific code for that or i just check that if timestamp=timestamp+24hours
     
  14. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Usually I would just take the current day and subtract 1 day from it and see if that is equal to the timestamp. Or if you need to, check if it's >= to the timestamp. The datetime class has several ways to do this. You don't really need to do the hours unless you want it to be 24 hours before the next daily reward is offered, but personally I wouldn't care if I person got an award at 11:59 pm and then their next reward at 12am. But you'll have to decide what works best for your daily reward system.

    It also depends on if you want to give reward streaks that reset if you don't claim your reward each day to how your logic may work.
     
  15. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    sure iam choosing first system its better
    and no reset for login thanks so much man really appreciate it :)