need help accessing game clock

Post here if you want to help developing something for FAF.

need help accessing game clock

Postby Thim » 08 Nov 2014, 03:02

I need to setup a random seed prior to when the normal seed is setup (as far as I can tell), so I need to setup something that gives me a way to make my calls to math.random() different every game. os.time() isn't working for me when I am using it in Blueprints.lua. Does anyone know what may be causing a problem, or know of another way to get random numbers without resorting to utilities.lua? (those methods also aren't working for me, and I don't think it's on my end)
Thim
Crusader
 
Posts: 26
Joined: 08 Nov 2014, 02:48
Has liked: 0 time
Been liked: 1 time
FAF User Name: Thim

Re: need help accessing game clock

Postby Sheeo » 12 Nov 2014, 14:27

Thim wrote:I need to setup a random seed prior to when the normal seed is setup (as far as I can tell), so I need to setup something that gives me a way to make my calls to math.random() different every game. os.time() isn't working for me when I am using it in Blueprints.lua. Does anyone know what may be causing a problem, or know of another way to get random numbers without resorting to utilities.lua? (those methods also aren't working for me, and I don't think it's on my end)


You can't call os.time from within the sim.

Why doesn't GetRandomFloat/Int in utilities.lua work for you? They're used throughout the entire codebase.
Support FAF on patreon: https://www.patreon.com/faf?ty=h

Peek at our continued development on github: https://github.com/FAForever
Sheeo
Councillor - Administrative
 
Posts: 1038
Joined: 17 Dec 2013, 18:57
Has liked: 109 times
Been liked: 233 times
FAF User Name: Sheeo

Re: need help accessing game clock

Postby Thim » 01 Dec 2014, 17:05

Why doesn't GetRandomFloat/Int in utilities.lua work for you? They're used throughout the entire codebase.


When I attempted to use these, I got the closest thing to a crash that supcom seems to give: the ACU is invisible and the score screen is blank. I was careful to use the methods in the same way that unit.lua did with artillery, but I still may have made a mistake. I currently think that the reason that it doesn't work is that something isn't set up by the time that the blueprints.lua runs, but is ready later in the program, but that's just my guess. As you can tell, I am not too well versed in forged alliance's code.
Thim
Crusader
 
Posts: 26
Joined: 08 Nov 2014, 02:48
Has liked: 0 time
Been liked: 1 time
FAF User Name: Thim

Re: need help accessing game clock

Postby Resin_Smoker » 05 Dec 2014, 15:42

Try GetGameTick or GetGameTime... Both are LUA functions listed in forged alliance lua reference: http://supcom.wikia.com/wiki/LUADOC_1.5.3599
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: need help accessing game clock

Postby ckitching » 16 Jan 2015, 13:33

Sheeo wrote:
Thim wrote:I need to setup a random seed prior to when the normal seed is setup (as far as I can tell), so I need to setup something that gives me a way to make my calls to math.random() different every game. os.time() isn't working for me when I am using it in Blueprints.lua. Does anyone know what may be causing a problem, or know of another way to get random numbers without resorting to utilities.lua? (those methods also aren't working for me, and I don't think it's on my end)


You can't call os.time from within the sim.

Why doesn't GetRandomFloat/Int in utilities.lua work for you? They're used throughout the entire codebase.


There's also GetSystemTimeSeconds(), which returns the system time as a fractional number of seconds (amusingly enough). It's probably millisecond-precise, plus floating point error.
User avatar
ckitching
Avatar-of-War
 
Posts: 229
Joined: 03 Jan 2015, 12:51
Has liked: 2 times
Been liked: 69 times
FAF User Name: ckitching

Re: need help accessing game clock

Postby Sheeo » 17 Jan 2015, 02:59

ckitching wrote:
Sheeo wrote:
Thim wrote:I need to setup a random seed prior to when the normal seed is setup (as far as I can tell), so I need to setup something that gives me a way to make my calls to math.random() different every game. os.time() isn't working for me when I am using it in Blueprints.lua. Does anyone know what may be causing a problem, or know of another way to get random numbers without resorting to utilities.lua? (those methods also aren't working for me, and I don't think it's on my end)


You can't call os.time from within the sim.

Why doesn't GetRandomFloat/Int in utilities.lua work for you? They're used throughout the entire codebase.


There's also GetSystemTimeSeconds(), which returns the system time as a fractional number of seconds (amusingly enough). It's probably millisecond-precise, plus floating point error.


That function is only available in the user state.

There is an awkwardly named sim-exposed function called "GetSystemTimeSecondsOnlyForProfileUse", but as the name suggests, you should not be using it for anything but profiling.
Support FAF on patreon: https://www.patreon.com/faf?ty=h

Peek at our continued development on github: https://github.com/FAForever
Sheeo
Councillor - Administrative
 
Posts: 1038
Joined: 17 Dec 2013, 18:57
Has liked: 109 times
Been liked: 233 times
FAF User Name: Sheeo

Re: need help accessing game clock

Postby Domino » 20 Jan 2015, 21:36

just use dofile(utilities.lua) in global.lua before blueprints.lua (if memeory serves correctly)
find where blueprints.lua is initialised from and use the above dofile from above.

blueprints.lua is loaded into a different "front end" user state and then stored in a metatable and passed to the user state when done
internal ofcourse. just load your utility files before blueprints.lua is loaded and you should be golden.
Domino
Priest
 
Posts: 315
Joined: 14 Mar 2012, 21:07
Has liked: 3 times
Been liked: 75 times


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest