Jump to content
Tonka

Function already registered for timers

Recommended Posts

Picking up X-Plane development again after a long hiatus.

When trying to initialise a timer in a script I get the error "function already registered for timers".

I see this error when using the following

timer.newTimer("TimerNew" , 1)

I see that a similar error was being reported for the IXEG 737 a while ago.

Does anyone know what causes this issue please?

I have no other timers in my scripts, and I've tried a variety of timer names.

Cheers.

Share this post


Link to post
Share on other sites

Solved:

I was initialising the Timer in the main() flight loop, so the Timer was being initialised every loop, hence the "function already registered" error. 

 

Share this post


Link to post
Share on other sites
On 6/10/2018 at 9:34 PM, Tonka said:

Solved:

I was initialising the Timer in the main() flight loop, so the Timer was being initialised every loop, hence the "function already registered" error. 

 

If you don't mind, could you post an example?

Share this post


Link to post
Share on other sites

Sure. I used a timer to make custom strobe lighting, with the associated spill light etc 

The timer is built outside of the main per frame loop, and stopped/started as necessary, according to the strobe light switch.

The StrobeFlash_1 function is ONLY called when the timer has run out, so i use it to show the strobe light for 1 frame every 1 second.

-- create timer outside of main loop so it is only created once
StrobeTimer_1 = timer.newTimer("StrobeFlash_1" , 1)             -- Create 1 second Timer - Function called when time = 0

-- main function to handle per frame stuff....
function Main()
    dref.setFloatV(dref_sim_StrobeBrightness, 1, 0)             -- Write to sim drefs for global lighting STROBE OFF
    dref.setInt(dref_sim_StobeFlashNow, 0)                      -- Write to sim drefs for global lighting STROBE OFF

    if StrobeSwitch == 0 then                                   -- If beacon turned off
        if StrobeTimer_1 ~= nil then                            -- And associated timer is alive, then
          timer.stop(StrobeTimer_1)                             -- Stop the timer
        end

        if StrobeSwitch ~=1 then                                -- If beacon turned on
          timer.reset(StrobeTimer_1)                            -- Reset the timer
        end                                                     -- So timer starts continuosly countingg down from 1 second to 0 seconds
    end
end

function StrobeFlash_1()                                        -- Called when time = 0 (so strobe is only on for 1 frame)
    dref.setFloatV(dref_sim_StrobeBrightness, 1, 1)		-- Write to sim drefs for global lighting STROBE ON
    dref.setInt(dref_sim_StobeFlashNow, 1)			-- Write to sim drefs for global lighting STROBE ON
    dref.setFloat(dref_NewStrobe, 1,)				-- Write to custom dref to set light to on ONLY when time = 0 
end
  

 

If the Timer is built inside the flight loop, we are technically saying "build this same timer" every frame. 

Instead, build the timer once, and start/stop/reset or alter it per frame as needed.

I'll post a video of the result shortly.

Edited by Tonka
  • Like 1

Share this post


Link to post
Share on other sites

Ah cool! Was beginning to wonder how many actual devs were in that Facebook group!

I could do with altering the colour of the entire screen when the strobe flashes, to really represent the burning retina experienced with real strobes!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×