Jump to content

Can’t get clock to work in Wherigo


granskog123

Recommended Posts

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.
 

 

 

 

Link to comment

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...

Link to comment
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?

Link to comment
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!

  • Love 1
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...