It is currently April 25th, 2024, 2:06 am

[Tip] Duplicate Time Measure with Localization

Discuss the use of Lua in Script measures.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

[Tip] Duplicate Time Measure with Localization

Post by smurfier »

This very small script will emulate the Time measure and will do so using the localization settings of the user's computer.

Time.lua

Code: Select all

PROPERTIES = {
Format = "";
}

function Initialize()
os.setlocale("","time")
end

function Update()
return os.date(PROPERTIES.Format,os.time())
end
In the skin:

Code: Select all

[Time]
Measure=Script
ScriptFile=Time.lua
Format="%B %d %Y"
NOTE: Lua does not support the use of # to remove leading zeros.

Original tip made by Yggdrasil.
Last edited by smurfier on October 2nd, 2011, 8:01 pm, edited 1 time in total.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: [Tip] Duplicate Time Measure with Localization

Post by poiru »

I would suggest calling os.setlocale() in Initialize(). It's also good to remember that the locale is process wide (even the Time measure itself will return a localized string after changing the locale through Lua).
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: [Tip] Duplicate Time Measure with Localization

Post by smurfier »

poiru wrote:I would suggest calling os.setlocale() in Initialize(). It's also good to remember that the locale is process wide (even the Time measure itself will return a localized string after changing the locale through Lua).
Changed my first post, thank you.

If using multiple measures, then it may be best to use just the initialize function with os.setlocale("","time").
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: [Tip] Duplicate Time Measure with Localization

Post by poiru »

It occurred to me that can break skins using Substitute= with Time measures (for example). Just something to keep in mind.