How to limit an action only once a day?

Hi, is there a way to allow the user to only do a certain action every once in a while? I put a fortune wheel in my game but users should be able to spin it only once a day. How can I do this? Can I use timer.performWithDelay()?

Store the time the user spins in a file. When the user returns, read the value and check to see if the time is >24 hours.

There are several ways to create/store persistent values, and since I wrote GBC Data Cabinet, I am partial to that method.



I offer a few ways.

  1. Use servers such as Gamesparks or Playfab for control. Gamesparks has code that is executed once a day, and you can write it in it. This is the safest way to do so.

  2. Use IO↓
    local path = system.pathForFile( "data.txt" , system.DocumentsDirectory )
    local fhd = ( path )
    Before the user runs the action, read the file and check the date of the last execution.
    If it is the same as today, the action will be cancelled. Otherwise, it will run. After running, open the file and record the date of this run.

This method is quite simple, but as long as the server is not used for control, users will be able to make changes by themselves!

For local storage, you can also implement a simple JSON load/save module by following this tutorial:

1 Like