Jump to content

Date and time information


MtnGoat50

Recommended Posts

I'm working on a cartridge that involves touring a park. One particular area of the park is closed in the Winter. Can I design the cartridge so it will automatically skip that area during the winter?

 

You could include some author code that uses the lua function os.date (google "lua os.date" for more info) to determine the current date and insert logic based on that. This is definitely stepping outside the builder :(

 

Here is some code (incomplete) that I have been playing with in case it helps:

 

dow = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }
month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }

function ztimerEvery5seconds:OnTick()
-- #GroupDescription=Script --
-- #Comment=Script Comment --

local i = os.date("!%c")
Wherigo.MessageBox{Text=[[]] .. i .. [[

Processed = ]] .. getdow(i) .. [[ ]] .. getdom(i) .. [[ ]]  .. getmonth(i) .. [[(]] .. getmonthnum(i) .. [[)]]  .. getyear(i)  .. [[ ]]  .. get24hour(i) .. [[:]] .. getmin(i) .. [[:]]  .. getsec(i),}
end

function getdow(t)
for j = 1 , 7, 1 do
if string.sub(dow[j], 1, 3) == string.sub(t,1,3) then
return dow[j]
end
end
end

function getmonth(t)
for j = 1 , 12, 1 do
if string.sub(month[j], 1, 3) == string.sub(t,5,7) then
return month[j]
end
end
end

function getmonthnum(t)
for j = 1 , 12, 1 do
if string.sub(month[j], 1, 3) == string.sub(t,5,7) then
return j
end
end
end

function getdom(t)
return tonumber(string.sub(t,9,10))
end

function getyear(t)
return tonumber(string.sub(t,21,24))
end

function get24hour(t)
return tonumber(string.sub(t,12,13))
end
function getmin(t)
return tonumber(string.sub(t,15,16))
end

function getsec(t)
return tonumber(string.sub(t,18,19))
end

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