Execute sim code periodically

Everything about mods can be found here.

Moderator: Morax

Execute sim code periodically

Postby C14 » 10 Feb 2018, 14:45

Hi,

what is the best way to execute some code that may change the sim periodically during a game,
say once a second or every n'th beat?
(context: I'd like to destroy units periodically that are outside of the map boundary)

Currently I am using ForkThread at the end of BeginSession in simInit.lua and WaitSeconds
in the thread function but altering the sim in another thread feels unsafe.
Is there a better way to execute code that affects the sim every n'th sim beat?
I've seen OnBeat and AddBeatFunction in ui\game\gamemain.lua but it seems to be only used in UI related stuff?
C14
 
Posts: 6
Joined: 03 Jul 2012, 21:03
Has liked: 0 time
Been liked: 0 time
FAF User Name: C14

Re: Execute sim code periodically

Postby speed2 » 10 Feb 2018, 14:50

ForkThread is the right and only way to do this.

So you're doing it correctly

It's not a "real" new thread as the whole sim runs in a single thread on the cpu anyway.
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: Execute sim code periodically

Postby C14 » 10 Feb 2018, 15:40

Ok, thanks a lot for the fast reply.
C14
 
Posts: 6
Joined: 03 Jul 2012, 21:03
Has liked: 0 time
Been liked: 0 time
FAF User Name: C14


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest