For any feature requests to either the Skyline Engine or the websites and forums please leave your suggestion here.

Access to System Time

Access to System Time

Postby Shando » 21 Mar 2015, 00:26

Hi All,

Just wondering if there is a way to access System Time? I know dt is available in onUpdate, but what about if I need to do something time specific outside of onUpdate?

Ideally, something as simple as time.getSystemTimeInMillis ( ) would suffice.

The main reason for this (rather than using the Timers which only fire at set intervals, and you can't access the time outside of these intervals) is for setting math.randomSeed ( ).

Alternatively, a function such as setRandomSeedTime ( ) where the randomSeed is set based on current System Time would be ok.

Thanks

Shando
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Access to System Time

Postby ant0N » 21 Mar 2015, 05:36

Hi! :)
If I understand correctly, it is easy to implement.
Code: Select all
second = os.time()
math.randomseed(os.time())
rand = math.random(-10,10)


if you want to get milliseconds, you can create a little function.
Code: Select all
millisecs = 0
function getMillisecs()
    millisecs = millisecs+1
    if millisecs >= 100 then millisecs = 0 end
end

and initialize the function in onUpdate()
Sorry for my English. :)
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Access to System Time

Postby Shando » 21 Mar 2015, 06:41

Hi ant0N,

Thanks for that, I hadn't even considered we had access to the "os" functions from Lua :oops:

Probably should get the devs to add the standard Lua functions we can use to the API documents??

Thanks again :D

Shando
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Access to System Time

Postby ant0N » 21 Mar 2015, 07:09

Sorry for my English. :)
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Access to System Time

Postby SolarPortal » 21 Mar 2015, 10:51

cool, great answer antON :D
Skyline should have access to all libraries included in lua 5.1, certain things can only be used in certain ways though lol :P
We could look at adding all the commands to the API, but that is a lot of work, and i honestly don't know what commands are usable to us.

@Shando: The input/output stuff works because you made that xml file reader in lua :P

From the onUpdate loop, you could store the deltatime in a global variable that is accessible across all your functions.

Code: Select all
timeDelta = 0

function onUpdate(dt)
    timeDelta = dt
end


Note for another requested lua feature: I have looked at upgrading to lua 5.3, but they changed a lot of the way things are done in 5.2. So it will take time, as the lua in skyline needs fully upgraded to be compatible. We can look at implementing our own "Bit32" library at some point.
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Access to System Time

Postby Shando » 21 Mar 2015, 14:29

From the onUpdate loop, you could store the deltatime in a global variable that is accessible across all your functions.


Good idea :D That's certainly the best way to go so that all functions react the same.

With regards to Lua 5.3, no worries, I changed the code I was using so it didn't rely on bit32. So, don't worry about that, as I'm sure there are more pressing issues ;)

I'll start a thread listing what Lua commands are available (that we know of) and, if it's stickied, then we can add more commands as we come across them.

Regards

Shando
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Access to System Time

Postby SolarPortal » 21 Mar 2015, 14:42

sounds good :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Access to System Time

Postby Shando » 21 Mar 2015, 14:52

Hi SP,

I have started the list with a post in the "Lua Scripting" section.

Shando
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Access to System Time

Postby SolarPortal » 21 Mar 2015, 15:04

yep, just had a look and i think it will be a great resource. :)

When it has been filled with all the possible commands, we can then look at adding it to the API.
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 8 guests

cron