September 16, 20241 yr Author 1 hour ago, mSparks said: then you tried to make it call XPLMFindDataRef... all of them. FWL get lets you "quickly" get a dataref value, it takes the form get("sim/flightmodel/position/theta") most usefull when you only want to use it once, e.g. see this example: https://github.com/X-Friese/FlyWithLua/blob/master/FlyWithLua/Scripts (disabled)/heading speed altitude instrument.lua Thank you so much for your helps. Now ı just try it with different pc and it works! I think the problem is with my computer and the way I downloaded Lua. Just one thing when ı run my program, I get a notification to check the quarantine file, and when I check where my code is, I see that it is in the quarantine file, but my code is working smoothly so far. I thought it could be about overwrite. Do you have any ideas about this?
September 17, 20241 yr 15 hours ago, Ahmet Ali said: to check the quarantine file, and when I check where my code is, I see that it is in the quarantine file that means the code is throwing some error. It should be in the logs somewhere. AutoATC Developer
September 17, 20241 yr sim/operation/override/override_planepath is an integer array. -- Define override dataref for plane path local dr_override_planepath = XPLMFindDataRef("sim/operation/override/override_planepath") -- Function to set override (1 to override, 0 to disable override) function setOverridePlanePath(override) XPLMSetDatai(dr_override_planepath, override) end if you want to continue to use the XPLM... functions continue here (I know you refactored your code already... here's an official example using it for example https://github.com/X-Friese/FlyWithLua/blob/master/FlyWithLua/Scripts (disabled)/VFR weather.lua#L6) Your error "attempt to call a nil value (global 'XPLMFindDataRef')" should come from something else. I am certainly using them in my scripts and do not have any special things in ./FlyWithLua/Modules apart from what the default installation brings. You have to use XPLMSetDatavi( DataRef, table, inIndex, inMax ) to set the array value. (See docs https://github.com/X-Friese/FlyWithLua/blob/master/docs/FlyWithLua_Manual_en.pdf page 86). XPLMSetDatavi(dr_override_planepath, { [0] = override }, 1, 1) -- (or maybe [1] = ..., I dont know currently how it works when you only want to start writing from index 1)
September 17, 20241 yr Author 55 minutes ago, mSparks said: that means the code is throwing some error. It should be in the logs somewhere. EDİT: A little misunderstanding. The code I tried on my friend's computer yesterday does not work. The reason it worked on his computer was because there was another draw multiaircraft script in the SDK, so my code does not work again and ı dont know why... I fixed what you said but the code still doesn't work. -- Define datarefs for multiplayer planes dataref("dr_plane_x", "sim/multiplayer/position/plane1_x", "writable") dataref("dr_plane_y", "sim/multiplayer/position/plane1_y", "writable") dataref("dr_plane_z", "sim/multiplayer/position/plane1_z", "writable") dataref("dr_plane_the", "sim/multiplayer/position/plane1_the", "writable") dataref("dr_plane_phi", "sim/multiplayer/position/plane1_phi", "writable") dataref("dr_plane_psi", "sim/multiplayer/position/plane1_psi", "writable") dataref("dr_plane_x2", "sim/multiplayer/position/plane2_x", "writable") dataref("dr_plane_y2", "sim/multiplayer/position/plane2_y", "writable") dataref("dr_plane_z2", "sim/multiplayer/position/plane2_z", "writable") dataref("dr_plane_the2", "sim/multiplayer/position/plane2_the", "writable") dataref("dr_plane_phi2", "sim/multiplayer/position/plane2_phi", "writable") dataref("dr_plane_psi2", "sim/multiplayer/position/plane2_psi", "writable") -- Define global plane position datarefs dataref("gPlaneX", "sim/flightmodel/position/local_x", "writable") dataref("gPlaneY", "sim/flightmodel/position/local_y", "writable") dataref("gPlaneZ", "sim/flightmodel/position/local_z", "writable") dataref("gPlaneTheta", "sim/flightmodel/position/theta", "writable") dataref("gPlanePhi", "sim/flightmodel/position/phi", "writable") dataref("gPlanePsi", "sim/flightmodel/position/psi", "writable") -- Define override planepath datarefs as an array of 20 boolean/integer values dataref("override_planepath", "sim/operation/override/override_planepath", "writable") -- Function to read current plane data (optional, if you want to print or log it) function readPlaneData() local plane_x = dr_plane_x local plane_y = dr_plane_y local plane_z = dr_plane_z local plane_theta = dr_plane_the local plane_phi = dr_plane_phi local plane_psi = dr_plane_psi local plane_x2 = dr_plane_x2 local plane_y2 = dr_plane_y2 local plane_z2 = dr_plane_z2 local plane_theta2 = dr_plane_the2 local plane_phi2 = dr_plane_phi2 local plane_psi2 = dr_plane_psi2 end -- Function to set plane data function setPlaneData(plane_x, plane_y, plane_z, plane_theta, plane_phi, plane_psi, plane_x2, plane_y2, plane_z2, plane_theta2, plane_phi2, plane_psi2) -- Set plane 1 data dr_plane_x = plane_x dr_plane_y = plane_y dr_plane_z = plane_z dr_plane_the = plane_theta dr_plane_phi = plane_phi dr_plane_psi = plane_psi -- Set plane 2 data dr_plane_x2 = plane_x2 dr_plane_y2 = plane_y2 dr_plane_z2 = plane_z2 dr_plane_the2 = plane_theta2 dr_plane_phi2 = plane_phi2 dr_plane_psi2 = plane_psi2 end -- Function to update aircraft positions function updateAircraft() local x = gPlaneX local y = gPlaneY local z = gPlaneZ local theta = gPlaneTheta local phi = gPlanePhi local psi = gPlanePsi -- Calculate positions for the two multiplayer planes relative to the player's aircraft local plane_x = x + 50.0 local plane_y = y local plane_z = z + 50.0 local plane_theta = theta local plane_phi = phi local plane_psi = psi local plane_x2 = x - 50.0 local plane_y2 = y local plane_z2 = z - 50.0 local plane_theta2 = theta local plane_phi2 = phi local plane_psi2 = psi -- Set the positions of both planes setPlaneData(plane_x, plane_y, plane_z, plane_theta, plane_phi, plane_psi, plane_x2, plane_y2, plane_z2, plane_theta2, plane_phi2, plane_psi2) -- Override planepath for the two AI aircraft -- Assuming indices 0 and 1 for the AI aircraft override_planepath[1] = 1 -- Enable override for AI aircraft 1 override_planepath[2] = 1 -- Enable override for AI aircraft 2 -- Update positions in the overridden paths -- For demonstration, we'll assume you need to set some parameters -- Replace with the actual way to set positions, if necessary -- For example: -- override_planepath[3] = {plane_x, plane_y, plane_z, plane_theta, plane_phi, plane_psi} -- Not required if it's just enabling end -- Update aircraft every frame do_every_frame("updateAircraft()")
September 17, 20241 yr Author 2 hours ago, flightwusel said: sim/operation/override/override_planepath is an integer array. -- Define override dataref for plane path local dr_override_planepath = XPLMFindDataRef("sim/operation/override/override_planepath") -- Function to set override (1 to override, 0 to disable override) function setOverridePlanePath(override) XPLMSetDatai(dr_override_planepath, override) end if you want to continue to use the XPLM... functions continue here (I know you refactored your code already... here's an official example using it for example https://github.com/X-Friese/FlyWithLua/blob/master/FlyWithLua/Scripts (disabled)/VFR weather.lua#L6) Your error "attempt to call a nil value (global 'XPLMFindDataRef')" should come from something else. I am certainly using them in my scripts and do not have any special things in ./FlyWithLua/Modules apart from what the default installation brings. You have to use XPLMSetDatavi( DataRef, table, inIndex, inMax ) to set the array value. (See docs https://github.com/X-Friese/FlyWithLua/blob/master/docs/FlyWithLua_Manual_en.pdf page 86). XPLMSetDatavi(dr_override_planepath, { [0] = override }, 1, 1) -- (or maybe [1] = ..., I dont know currently how it works when you only want to start writing from index 1) THANK YOU!!!!!! The program is working properly, I did the same as you said, I had to create an array and send the values that way with XPLMSetDatavi , as you said. Extra note: We can use datarefs and XPLMdatarefs together without any problems.
Create an account or sign in to comment