+granskog123 Posted February 22, 2023 Share Posted February 22, 2023 I’m building an Wherigo where you have to run to a zone before a timer ends. The cartridge works great, the problem is just that the timer pauses when the app closes. Users will be asked to turn off ”auto lock” on their phone, but a cheater could technically turn their phone off or just close the app and walk to the goal in their own pace. My thought was to use the current time to confirm that the timer hasn’t ended, once the user reaches the “goal” zone. After some search i found this page : The cartridge returns the current time when that code is put into the author script, but I haven’t been able to create a variable that does it. Could someone help me? I’m using earwigo. Quote Link to comment
+Mangatome Posted February 24, 2023 Share Posted February 24, 2023 I'm not sure whether the problem may be specific to earwigo, but in theory calling os.date() in the lua code should give you the time on the player device when that code is executed, not the time when you wrote the code. What I would do is, when you want the timer to start, to assign the date to a variable, for example timer_start = os.date() and then when people reach the goal zone if os.difftime(timer_start, os.date()) > 60 then -- More than 60 seconds have elapsed: player was too slow. else -- Player is on time... end Not sure how to put that into earwigo, though... Quote Link to comment
+granskog123 Posted February 26, 2023 Author Share Posted February 26, 2023 On 2/24/2023 at 2:26 PM, Mangatome said: I'm not sure whether the problem may be specific to earwigo, but in theory calling os.date() in the lua code should give you the time on the player device when that code is executed, not the time when you wrote the code. What I would do is, when you want the timer to start, to assign the date to a variable, for example timer_start = os.date() and then when people reach the goal zone if os.difftime(timer_start, os.date()) > 60 then -- More than 60 seconds have elapsed: player was too slow. else -- Player is on time... end Not sure how to put that into earwigo, though... Not sure if this is is specific to earwigo or if I am doing something wrong, but running that code returns this error: cartridge.lua:282: bad argument #1 to 'difftime' (number expected, got string). Are the dates supposed to be numbers? Quote Link to comment
+Mangatome Posted February 28, 2023 Share Posted February 28, 2023 I think I mistook os.date() for os.time(). What if you use: timer_start = os.time() and if os.difftime(timer_start, os.time()) > 60 then -- More than 60 seconds have elapsed: player was too slow. else -- Player is on time... end ? 1 Quote Link to comment
+granskog123 Posted March 2, 2023 Author Share Posted March 2, 2023 On 2/28/2023 at 3:55 PM, Mangatome said: I think I mistook os.date() for os.time(). What if you use: timer_start = os.time() and if os.difftime(timer_start, os.time()) > 60 then -- More than 60 seconds have elapsed: player was too slow. else -- Player is on time... end ? Now it works, thanks for the help! 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.