Jump to content
Jack Skieczius

Setting default dataref values on start up?

Recommended Posts

So one of the things that erks me the most about X-Plane is that it has some things set on as default. These things range from bleeds being set to all(5) and cowl flaps set to 0.75

When I started coding in lua just a few days now, I realized I could set these values I wanted in these datarefs at start....or so I thought.

Here is the bit of simple code I wrote that I believed would do the trick. It is located at the very beginning of a lua file that is called outside of any function.

--list of things i want to start the sim with
dref_bleed =    xp.getDataref("sim/cockpit2/pressurization/actuators/bleed_air_mode")
dref_boot =    xp.getDataref("sim/cockpit2/ice/ice_surface_boot_on")
dref_APUstart = xp.getDataref("sim/cockpit2/electrical/APU_starter_switch")
dref_cowl =    xp.getDataref("sim/cockpit2/engine/actuators/cowl_flap_ratio")


xp.setInt( dref_bleed, 0) --setting the bleeds to zero on startup
xp.setInt( dref_boot, 1)  --sets boot air to norm
xp.setInt( dref_APUstart, 0) --sets the apu to off on startup
xp.setFloatV(dref_cowl, 1, 0, 0) -- setts the cowls to close.

So what happens is these values sometimes get set when X-Plane starts, but sometimes they get reverted back to the default value that X-Plane has decided. It will work if I reboot Gizmo and it will work if i reload the aircraft after changing and saving a setting to the acf file.

The settings will revert back to default also if you change your aircraft location or reloading it.

I was thinking of using the Events.OnAircraftLoad() but I see it currently doesn't work.

I figure it wouldn't work if i placed it in function main() since i dont want these values set every second, but rather just once on startup.

Is there a way around any of this to make it work each time it would be expected to work?

Thanks.

Share this post


Link to post
Share on other sites
I was thinking of using the Events.OnAircraftLoad() but I see it currently doesn't work.

jack, is there some reasoning behind this statement other than just your own observations?  is this a known bug?   I just beat my head against the wall for something like 3 hours yesterday on my plugin...because on aircraft load, my initializations were not "sticking" and causing major haywire with my toggle datarefs.  loading an aiport  location causes my initializations to work..but not aircraft load...it is HIGHLY annoying.  Normally I would just take it up with Ben/Austin, but Ben's out for a week and Austin isn't quite accessible at the moment.  If you're seeing the same thing, then maybe it's not just me.  

i'm going to try a deferred initialized flight loop and see if that works out to be a bit more reliable.

http://www.xsquawkbox.net/xpsdk/mediawiki/DeferredInitialization

Share this post


Link to post
Share on other sites

A; the events documentation is crammed into the auto-parser for now.

Pay close attention (copy paste and modify) the example events in the docs.

I'd try this:



function setDefaults()
  xp.setInt( dref_bleed, 0) --setting the bleeds to zero on startup
  xp.setInt( dref_boot, 1)  --sets boot air to norm
  xp.setInt( dref_APUstart, 0) --sets the apu to off on startup
  xp.setFloatV(dref_cowl, 1, 0, 0) -- setts the cowls to close.
end

function OnBoot()
  dref_bleed =    xp.getDataref("sim/cockpit2/pressurization/actuators/bleed_air_mode")
  dref_boot =    xp.getDataref("sim/cockpit2/ice/ice_surface_boot_on")
  dref_APUstart = xp.getDataref("sim/cockpit2/electrical/APU_starter_switch")
  dref_cowl =    xp.getDataref("sim/cockpit2/engine/actuators/cowl_flap_ratio")

  setDefaults()
end

function OnAirportChanged()
  setDefaults()
end

Further to Tom's comments:

Saying something doesn't work without telling me explicitly how you proved it, preferably with a code snippet, is going to get you ignored.

There are definitely bugs and typos in Gizmo, but more often than not its user or usage error.

Share this post


Link to post
Share on other sites

jack, is there some reasoning behind this statement other than just your own observations?  is this a known bug?   I just beat my head against the wall for something like 3 hours yesterday on my plugin...because on aircraft load, my initializations were not "sticking" and causing major haywire with my toggle datarefs.  loading an aiport  location causes my initializations to work..but not aircraft load...it is HIGHLY annoying.  Normally I would just take it up with Ben/Austin, but Ben's out for a week and Austin isn't quite accessible at the moment.  If you're seeing the same thing, then maybe it's not just me.  

i'm going to try a deferred initialized flight loop and see if that works out to be a bit more reliable.

http://www.xsquawkbox.net/xpsdk/mediawiki/DeferredInitialization

Tom,

Please make it explicitly clear by saying Ben S or Ben R.

Lots of Gizmo users wont understand some of the concepts you allude to here. Defered Init has 0 use in this context either. :)

Share this post


Link to post
Share on other sites

Ah, thanks Ben,

I see what you did there, and it makes total sense now.

And the code works like a charm.

Also , i would like to point out that coding in Gizmo is a joy, most especially when Gizmo finds an error and you are given a very funny message to read. Makes making mistakes fun? er, well maybe. At least i don't feel so bad and i get a good laugh.

Share this post


Link to post
Share on other sites

Does function OnBoot() reboot Gizmo when an aircraft is loaded for anyone else?

I am calling that function in an onboot script, to set up some datarefs, similar to what Jack is doing, but the drefs i am writing to do not change on acf load, only when i hit the reboot Gizmo button. I am currently using 11.4.25 and have a simple that should set the payload to zero on boot.

function OnBoot()

xp.setFloat ( dref_payload, 0 )

end

Share this post


Link to post
Share on other sites

how do you define dref_payload?

Best thing to do is read your Log.txt files and add some logging.debug("double checks") at this point in Gizmos life. Need better debugging tools.

Share this post


Link to post
Share on other sites

Thanks for the quick reply Ben.

I am defining the dref in a seperate drefs.lua file, thus;

dref_payload = xp.getDataref("sim/flightmodel/weight/m_fixed")

I have broken all my script parts down into separate files, similar to your F-16 project.

I'll try calling a logging.debug message from an OnBoot() function now.

Share this post


Link to post
Share on other sites

Ok, i am seeing my logging.debug message in the log.txt, which i have added in to the OnBoot() function;

function OnBoot()

logging.debug( "gizmo scripts booted" )

xp.setFloat ( dref_payload, 0 )

end

But my payload stays at whatever value X-Plane loads the acf with, until i hit the reboot gizmo button.

My log.txt lists the same messages on initial load, as it does when i use the reboot gizmo button, so the same things appear to be happening. Is there a OnAircraftChanged() function we can call? I see something along those lines is listed in the log.txt, but nothing in the Events API;


.....
Loading airplane number 0 with Aircraft/1 My Builds/Jaguar 9.67 0.65/Jaguar_Clean.acf.
Gizmo: AircraftChanged()
....

Share this post


Link to post
Share on other sites

Grab yourself an updated copy of the API dox, it has events listed in it now.

https://sites.google.com/a/x-plugins.com/www/gizmo/api

_Events.OnAircraftLoad()

function OnAircraftLoad()

--This function needs to accept an index number telling us which aircraft changed, currently it does not.

--You know -an- aircraft was loaded, you don't know which one, it's kind of irrelevant anyway due to engine issues.(??? - br)

end

Share this post


Link to post
Share on other sites

I think my locally saved API is up to date, but i'll grab it again to be sure. - That's a really useful thing to be able to do by the way, my broadband is pants and i cant always get online!

Using;

function OnAircraftLoad()       

xp.setFloat ( dref_payload, 0 )

end

I see no effect in sim, just like Jack above.

Let me know if i am approaching the boundary of paid support won't you Ben.

Thanks.

Share this post


Link to post
Share on other sites

Annoyance confirmed.

Here's my test. Please submit complete examples, it makes my life much much easier. :P


dref_gear_handle = xp.getDataref("sim/cockpit/switches/gear_handle_status")

function OnBoot()

xp.setInt( dref_gear_handle, 0 )

local sf = sound.load( xp.getXPlaneFolder() .. "Aircraft/Fighters/Viggen JA37/sounds/alert/VIGGEN37 pull.wav" )
sound.play( sf )

end

Loading the aircraft, writing the code and then pressing the reboot button, this code works as expected.

Reloading the aicraft, the gear handle remains down.

This code was tested against the Cirrus Jet.

Conclusion: OnBoot is not a suitable place to work with some parts of X-Plane.

Remedy: A new event is needed, OnBoot is a suitable place to create new datarefs so that the OBJ8 engine can "find and bind" them to animations, etc.

Hack: Use a short duration timer to give X-Plane a chance to ready itself.



dref_gear_handle = xp.getDataref("sim/cockpit/switches/gear_handle_status")

function OnBoot()
timer.newOneShot( "normalize_defaults", 0.1 )
end

function normalize_defaults()
xp.setInt( dref_gear_handle, 0 )
end

Share this post


Link to post
Share on other sites

New Event: OnFirstFrame

A new event was added to allow for a consistent place for authors to perform init of their dataref defaults.

This event is seperate from OnBoot and runs _AFTER_ the ACF has completed loading.

Suggestions/comments welcome. This stuff needs to make sense to you guys as well. :P

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.

×