September 14, 20241 yr Greetings, my aim is to draw 2 AI aircraft around the user aircraft so that ı write this code with lua. As seen in the code, the positions of my AI aircrafs change in each frame to be next to my user aircraft as ı wanted, but the angles are not updated in any way. In other words, two AI aircraft are flying next to my user aircraft and following my user aircraft, but since the angles are not updated, they take ridiculous shapes. -- Define datarefs local dr_plane_x = XPLMFindDataRef("sim/multiplayer/position/plane1_x") local dr_plane_y = XPLMFindDataRef("sim/multiplayer/position/plane1_y") local dr_plane_z = XPLMFindDataRef("sim/multiplayer/position/plane1_z") local dr_plane_the = XPLMFindDataRef("sim/multiplayer/position/plane1_the") local dr_plane_phi =XPLMFindDataRef("sim/multiplayer/position/plane1_phi") local dr_plane_psi = XPLMFindDataRef("sim/multiplayer/position/plane1_psi") local dr_plane_x2 = XPLMFindDataRef("sim/multiplayer/position/plane2_x") local dr_plane_y2 = XPLMFindDataRef("sim/multiplayer/position/plane2_y") local dr_plane_z2 = XPLMFindDataRef("sim/multiplayer/position/plane2_z") local dr_plane_the2 = XPLMFindDataRef("sim/multiplayer/position/plane2_the") local dr_plane_phi2 = XPLMFindDataRef("sim/multiplayer/position/plane2_phi") local dr_plane_psi2 = XPLMFindDataRef("sim/multiplayer/position/plane2_psi") -- Example function to read values function readPlaneData() local plane_x = XPLMGetDatad(dr_plane_x) local plane_y = XPLMGetDatad(dr_plane_y) local plane_z = XPLMGetDatad(dr_plane_z) local plane_theta = XPLMGetDataf(dr_plane_the) local plane_phi = XPLMGetDataf(dr_plane_phi) local plane_psi = XPLMGetDataf(dr_plane_psi) local plane_x2 = XPLMGetDatad(dr_plane_x2) local plane_y2 = XPLMGetDatad(dr_plane_y2) local plane_z2 = XPLMGetDatad(dr_plane_z2) local plane_theta2 = XPLMGetDataf(dr_plane_the2) local plane_phi2 = XPLMGetDataf(dr_plane_phi2) local plane_psi2 = XPLMGetDataf(dr_plane_psi2) end 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 XPLMSetDatad(dr_plane_x, plane_x) XPLMSetDatad(dr_plane_y, plane_y) XPLMSetDatad(dr_plane_z, plane_z) XPLMSetDataf(dr_plane_the, plane_theta) XPLMSetDataf(dr_plane_phi, plane_phi) XPLMSetDataf(dr_plane_psi, plane_psi) -- Set plane 2 data XPLMSetDatad(dr_plane_x2, plane_x2) XPLMSetDatad(dr_plane_y2, plane_y2) XPLMSetDatad(dr_plane_z2, plane_z2) XPLMSetDataf(dr_plane_the2, plane_theta2) XPLMSetDataf(dr_plane_phi2, plane_phi2) XPLMSetDataf(dr_plane_psi2, plane_psi2) -- Print for debug after setting values end local gPlaneX = XPLMFindDataRef("sim/flightmodel/position/local_x"); local gPlaneY = XPLMFindDataRef("sim/flightmodel/position/local_y"); local gPlaneZ = XPLMFindDataRef("sim/flightmodel/position/local_z"); local gPlaneTheta = XPLMFindDataRef("sim/flightmodel/position/theta"); local gPlanePhi = XPLMFindDataRef("sim/flightmodel/position/phi"); local gPlanePsi = XPLMFindDataRef("sim/flightmodel/position/psi"); function updateaircraft() local x = XPLMGetDatad(gPlaneX); local y = XPLMGetDatad(gPlaneY); local z = XPLMGetDatad(gPlaneZ); local theta = XPLMGetDataf(gPlaneTheta); local phi = XPLMGetDataf(gPlanePhi); local psi = XPLMGetDataf(gPlanePsi); local plane_x = x + 50; local plane_y = y; local plane_z = z + 50; local plane_theta = theta; local plane_phi = phi; local plane_psi = psi; local plane_x2 = x - 50; local plane_y2 = y; local plane_z2 = z - 50; local plane_theta2 = theta; local plane_phi2 = phi; local plane_psi2 = psi; setPlaneData(plane_x, plane_y, plane_z, plane_theta, plane_phi, plane_psi, plane_x2, plane_y2, plane_z2, plane_theta2, phi2, plane_psi2) end do_every_frame("updateaircraft()") The angles of my AI planes change completely randomly, but I want them to be the same as my user aircraft. Can you please help me solve this problem?
September 14, 20241 yr As far as I can tell from the code, you're forgetting to use distinct Theta, Phi an Psi for "Plane 1" and using the same variables you use to store you plane data in "updateaircraft()/0". Actually you make the same omission regarding the other referential variables too... You're using a separate collection of variables for plane 2 though. Nah... I was wrong... You are not using the wrong variables ... Never used LUA scripting, and this is all "Chinese" to me, but from such an "unbiased" perspective this is what I could find... (NOTHING actually, after editing above 🤣) Only minor modification I would do would be to use only a follower aircraft triple of Theta / PhI / Psi since both use the same as your aircraft, so, in "updateaircraft" I would pass only one triple of variables to "setPlaneData" for those variables... and use the same Theta / Phi and Psi formal parameters in "setPlaneData" to update the datarefs of both followers... Edited September 14, 20241 yr by jcomm Flying gliders since 1980 Flightsimming since 1992 AMD Ryzen 5600x, 32GB RAM, GPU Nvidia RTX 3060 Ti 8 GB, 1 TB and 500 GB nvme2 SSD drives, HP 27" 60Hz LED monitor @ 1920x1080, T16000, Hotas from old X52 Pro, Saitek Combat Rudder Pro (2010 model)
September 14, 20241 yr 2 hours ago, Ahmet Ali said: XPLMGetDataf XPLMSetDataf how are you getting these functions into lua? x(t)lua uses find_dataref fwl uses get and set. AutoATC Developer
September 14, 20241 yr Author 11 hours ago, mSparks said: how are you getting these functions into lua? x(t)lua uses find_dataref fwl uses get and set. Any help would be greatly appreciated ı am new at this topic ı would be very glad if you can you explain me with more detail please. As far as I understand so far, there is no need to introduce datarefs or XPLMdatarefs when I using flywith lua. But should I get these function from somewhere if ı use XLua or XTLua ? for example like this ?? -- first we need ffi module (variable must be declared local) local ffi = require("ffi") -- find the right lib to load local XPLMlib = "" if SYSTEM == "IBM" then -- Windows OS (no path and file extension needed) if SYSTEM_ARCHITECTURE == 64 then XPLMlib = "XPLM_64" -- 64bit else XPLMlib = "XPLM" -- 32bit end elseif SYSTEM == "LIN" then -- Linux OS (we need the path "Resources/plugins/" here for some reason) if SYSTEM_ARCHITECTURE == 64 then XPLMlib = "Resources/plugins/XPLM_64.so" -- 64bit else XPLMlib = "Resources/plugins/XPLM.so" -- 32bit end elseif SYSTEM == "APL" then -- Mac OS (we need the path "Resources/plugins/" here for some reason) XPLMlib = "Resources/plugins/XPLM.framework/XPLM" -- 64bit and 32 bit else return -- this should not happen end -- load the lib and store in local variable local XPLM = ffi.load(XPLMlib) and last question what is the difference between XPLMGetDataf and XPLM.XPLMGetDataf
September 15, 20241 yr 6 hours ago, Ahmet Ali said: Any help would be greatly appreciated ı am new at this topic ı would be very glad if you can you explain me with more detail please. No problem, always a pleasure to point a new XP dev in the right direction. 6 hours ago, Ahmet Ali said: when I using flywith lua..... if ı use XLua or XTLua FWL github https://github.com/X-Friese/FlyWithLua/tree/master XLua github https://github.com/X-Plane/XLua XTLua gihub (fork of Xlua with multithreading and a few other things added, we use for several tubliners systems, spun out of the Sparky744) https://github.com/mSparks43/XTLua SASL https://1-sim.com/ Gizmo64 https://gizmo64.com/ Each of these does basically the same thing, but they also come with more or less "extras" depending on what you need - more features = more complex stuff to learn. _____ 6 hours ago, Ahmet Ali said: what is the difference between XPLMGetDataf and XPLM.XPLMGetDataf If you dont have it already, you'll want DRE: https://developer.x-plane.com/tools/datarefeditor/ XPLM.... are (generally) the actual functions provided by the xplane SDK, written in C. For sanity I would recommend avoiding them unless you are writing them in C. documentation for them, are e.g. here https://developer.x-plane.com/sdk/XPLMGetDataf/ That said, there is a C++ sample of what you are trying to do here: https://developer.x-plane.com/code-sample/drawaircraft/ Using Lua has the advantage of not needing to compile it by OS prior to use, and, depending on which (of the above) lua engines you use, lots of otherwise hard stuff already done for you. If you go with FWL, the code to access datarefs will look like dataref("dr_plane_x", "sim/multiplayer/position/plane1_x") function showX() print(dr_plane_x) end do_every_draw('showX()') same in x(t)lua would be local dr_plane_x = find_dataref("sim/multiplayer/position/plane1_x") function after_physics() print(dr_plane_x) end FWL has lots of code samples in scripts(disabled) xlua you find used in all the default aircraft Edited September 15, 20241 yr by mSparks AutoATC Developer
September 15, 20241 yr FlyWithLua has XPLMFindDataRef(), XPLMSetDataf(), ... built-in like Ahmet uses them. You do not have to do the `require("ffi")` dance to use them. By the way I like this explicit API more than the implicit variable binding with dataref(). So what you do with DataRefs looks totally correct. I stumbled over your readPlaneData() which only sets local variables ("local" is the function scope in this case [https://www.lua.org/pil/4.2.html]) but does not return anything. But you are not using that function anywhere so we can also ignore that. So it must be something about the DataRefs to set AI plane positions and angles. It wouldn't explain random jumping, but maybe you have to set sim/operation/override/override_planepath? (array index 1 for AI #1). I've found a reference to it here https://forums.x-plane.org/index.php?/forums/topic/219328-controlling-ai-aircraft-in-x-plane-11/&do=findComment&comment=2375823 (mentioning that it had to be set on every frame). Maybe you can get some ideas from https://forums.x-plane.org/index.php?/files/file/50534-formation-flying-flywithlua-script/
September 15, 20241 yr Author 11 hours ago, mSparks said: No problem, always a pleasure to point a new XP dev in the right direction. FWL github https://github.com/X-Friese/FlyWithLua/tree/master XLua github https://github.com/X-Plane/XLua XTLua gihub (fork of Xlua with multithreading and a few other things added, we use for several tubliners systems, spun out of the Sparky744) https://github.com/mSparks43/XTLua SASL https://1-sim.com/ Gizmo64 https://gizmo64.com/ Thank you for your helps ı will continue to my researchs.
September 15, 20241 yr Author 2 hours ago, flightwusel said: It wouldn't explain random jumping, but maybe you have to set sim/operation/override/override_planepath? (array index 1 for AI #1). I've found a reference to it here https://forums.x-plane.org/index.php?/forums/topic/219328-controlling-ai-aircraft-in-x-plane-11/&do=findComment&comment=2375823 (mentioning that it had to be set on every frame). I am grateful for your help. I can't try it now because I will be abroad for 2 days but The reference you sent seems to be very useful for me.
September 15, 20241 yr 4 hours ago, Ahmet Ali said: Thank you for your helps ı will continue to my researchs. 👍 in terms of the rest. https://developer.x-plane.com/code-sample/drawaircraft/ for (AircraftIndex=1; AircraftIndex<8; AircraftIndex++) XPLMDisableAIForPlane(AircraftIndex); So I expect the randomness in their direction is the AI trying to fly the plane, disabling the AI rather than overriding the flight path will likely have the benefit of the other aircraft otherwise "flying" by the flight model when not getting data. and On 9/14/2024 at 7:15 AM, Ahmet Ali said: setPlaneData(plane_x, plane_y, plane_z, plane_theta, plane_phi, plane_psi, plane_x2, plane_y2, plane_z2, plane_theta2, phi2, plane_psi2) probably not setting plane2 phi Edited September 15, 20241 yr by mSparks AutoATC Developer
September 16, 20241 yr Author 12 hours ago, mSparks said: 👍 in terms of the rest. https://developer.x-plane.com/code-sample/drawaircraft/ for (AircraftIndex=1; AircraftIndex<8; AircraftIndex++) XPLMDisableAIForPlane(AircraftIndex); So I expect the randomness in their direction is the AI trying to fly the plane, disabling the AI rather than overriding the flight path will likely have the benefit of the other aircraft otherwise "flying" by the flight model when not getting data. and probably not setting plane2 phi 19 hours ago, flightwusel said: FlyWithLua has XPLMFindDataRef(), XPLMSetDataf(), ... built-in like Ahmet uses them. You do not have to do the `require("ffi")` dance to use them. By the way I like this explicit API more than the implicit variable binding with dataref(). So what you do with DataRefs looks totally correct. I stumbled over your readPlaneData() which only sets local variables ("local" is the function scope in this case [https://www.lua.org/pil/4.2.html]) but does not return anything. But you are not using that function anywhere so we can also ignore that. So it must be something about the DataRefs to set AI plane positions and angles. It wouldn't explain random jumping, but maybe you have to set sim/operation/override/override_planepath? (array index 1 for AI #1). I've found a reference to it here https://forums.x-plane.org/index.php?/forums/topic/219328-controlling-ai-aircraft-in-x-plane-11/&do=findComment&comment=2375823 (mentioning that it had to be set on every frame). Maybe you can get some ideas from https://forums.x-plane.org/index.php?/files/file/50534-formation-flying-flywithlua-script/ As you told me ı fixed my code(I share my code below) but my angles are still not updating. I didnt get any error from X-plane and flywithlua but when ı run this code on terminal it gives me this error: lua:4: attempt to call a nil value (global 'XPLMFindDataRef') stack traceback: C:\X-Plane\Resources\plugins\FlyWithLua\Scripts\world.lua:4: in main chunk [C]: in ? -- Define datarefs local dr_plane_x = XPLMFindDataRef("sim/multiplayer/position/plane1_x") local dr_plane_y = XPLMFindDataRef("sim/multiplayer/position/plane1_y") local dr_plane_z = XPLMFindDataRef("sim/multiplayer/position/plane1_z") local dr_plane_the = XPLMFindDataRef("sim/multiplayer/position/plane1_the") local dr_plane_phi = XPLMFindDataRef("sim/multiplayer/position/plane1_phi") local dr_plane_psi = XPLMFindDataRef("sim/multiplayer/position/plane1_psi") local dr_plane_x2 = XPLMFindDataRef("sim/multiplayer/position/plane2_x") local dr_plane_y2 = XPLMFindDataRef("sim/multiplayer/position/plane2_y") local dr_plane_z2 = XPLMFindDataRef("sim/multiplayer/position/plane2_z") local dr_plane_the2 = XPLMFindDataRef("sim/multiplayer/position/plane2_the") local dr_plane_phi2 = XPLMFindDataRef("sim/multiplayer/position/plane2_phi") local dr_plane_psi2 = XPLMFindDataRef("sim/multiplayer/position/plane2_psi") -- 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 -- Example function to read values function readPlaneData() local plane_x = XPLMGetDatad(dr_plane_x) local plane_y = XPLMGetDatad(dr_plane_y) local plane_z = XPLMGetDatad(dr_plane_z) local plane_theta = XPLMGetDataf(dr_plane_the) local plane_phi = XPLMGetDataf(dr_plane_phi) local plane_psi = XPLMGetDataf(dr_plane_psi) local plane_x2 = XPLMGetDatad(dr_plane_x2) local plane_y2 = XPLMGetDatad(dr_plane_y2) local plane_z2 = XPLMGetDatad(dr_plane_z2) local plane_theta2 = XPLMGetDataf(dr_plane_the2) local plane_phi2 = XPLMGetDataf(dr_plane_phi2) local plane_psi2 = XPLMGetDataf(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 XPLMSetDatad(dr_plane_x, plane_x) XPLMSetDatad(dr_plane_y, plane_y) XPLMSetDatad(dr_plane_z, plane_z) XPLMSetDataf(dr_plane_the, plane_theta) XPLMSetDataf(dr_plane_phi, plane_phi) XPLMSetDataf(dr_plane_psi, plane_psi) -- Set plane 2 data XPLMSetDatad(dr_plane_x2, plane_x2) XPLMSetDatad(dr_plane_y2, plane_y2) XPLMSetDatad(dr_plane_z2, plane_z2) XPLMSetDataf(dr_plane_the2, plane_theta2) XPLMSetDataf(dr_plane_phi2, plane_phi2) XPLMSetDataf(dr_plane_psi2, plane_psi2) end local gPlaneX = XPLMFindDataRef("sim/flightmodel/position/local_x") local gPlaneY = XPLMFindDataRef("sim/flightmodel/position/local_y") local gPlaneZ = XPLMFindDataRef("sim/flightmodel/position/local_z") local gPlaneTheta = XPLMFindDataRef("sim/flightmodel/position/theta") local gPlanePhi = XPLMFindDataRef("sim/flightmodel/position/phi") local gPlanePsi = XPLMFindDataRef("sim/flightmodel/position/psi") -- Function to update aircraft positions function updateAircraft() local x = XPLMGetDatad(gPlaneX) local y = XPLMGetDatad(gPlaneY) local z = XPLMGetDatad(gPlaneZ) local theta = XPLMGetDataf(gPlaneTheta) local phi = XPLMGetDataf(gPlanePhi) local psi = XPLMGetDataf(gPlanePsi) local plane_x = x + 50 local plane_y = y local plane_z = z + 50 local plane_theta = theta local plane_phi = phi local plane_psi = psi local plane_x2 = x - 50 local plane_y2 = y local plane_z2 = z - 50 local plane_theta2 = theta local plane_phi2 = phi local plane_psi2 = psi -- Enable plane path override setOverridePlanePath(1) -- 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) -- Disable plane path override after setting values (optional) -- setOverridePlanePath(0) end -- Update aircraft every frame do_every_frame("updateAircraft()")
September 16, 20241 yr 3 hours ago, Ahmet Ali said: lua:4: attempt to call a nil value (global 'XPLMFindDataRef') pretty sure that means XPLMFindDataRef is not defined, contrary to what flightwusel said, I dont think FWL defines them, what code sample/documetnation are you basing this code off? the correct way to map a dataref to a FWL variable is, instead of local dr_plane_x = XPLMFindDataRef("sim/multiplayer/position/plane1_x") .... local plane_x = XPLMGetDatad(dr_plane_x) you simply do dataref("plane_x","sim/multiplayer/position/plane1_x") rather than being a pointer, plane_x is then a proper lua variable, that you can set with plane_x = and compare with <,>,>= etc and fwl will handle the underlying calls to the xplane SDK. AutoATC Developer
September 16, 20241 yr Author 1 hour ago, mSparks said: pretty sure that means XPLMFindDataRef is not defined, contrary to what flightwusel said, I dont think FWL defines them, what code sample/documetnation are you basing this code off? the correct way to map a dataref to a FWL variable is, instead of local dr_plane_x = XPLMFindDataRef("sim/multiplayer/position/plane1_x") .... local plane_x = XPLMGetDatad(dr_plane_x) you simply do dataref("plane_x","sim/multiplayer/position/plane1_x") rather than being a pointer, plane_x is then a proper lua variable, that you can set with plane_x = and compare with <,>,>= etc and fwl will handle the underlying calls to the xplane SDK. I did it as you told me, but now ı get error again and error says: attempt to perform arithmetic on local "x" (a nil value) . İt gives error for this line local plane_x = x + 50 -- Define datarefs using modern get/set functions with the new dataref format dataref("dr_plane_x", "sim/multiplayer/position/plane1_x") dataref("dr_plane_y", "sim/multiplayer/position/plane1_y") dataref("dr_plane_z", "sim/multiplayer/position/plane1_z") dataref("dr_plane_the", "sim/multiplayer/position/plane1_the") dataref("dr_plane_phi", "sim/multiplayer/position/plane1_phi") dataref("dr_plane_psi", "sim/multiplayer/position/plane1_psi") dataref("dr_plane_x2", "sim/multiplayer/position/plane2_x") dataref("dr_plane_y2", "sim/multiplayer/position/plane2_y") dataref("dr_plane_z2", "sim/multiplayer/position/plane2_z") dataref("dr_plane_the2", "sim/multiplayer/position/plane2_the") dataref("dr_plane_phi2", "sim/multiplayer/position/plane2_phi") dataref("dr_plane_psi2", "sim/multiplayer/position/plane2_psi") -- Define override dataref for plane path dataref("dr_override_planepath", "sim/operation/override/override_planepath") -- Function to set override (1 to override, 0 to disable override) --function setOverridePlanePath(override) --set(dr_override_planepath, override) --end -- Example function to read values function readPlaneData() local plane_x = get(dr_plane_x) local plane_y = get(dr_plane_y) local plane_z = get(dr_plane_z) local plane_theta = get(dr_plane_the) local plane_phi = get(dr_plane_phi) local plane_psi = get(dr_plane_psi) local plane_x2 = get(dr_plane_x2) local plane_y2 = get(dr_plane_y2) local plane_z2 = get(dr_plane_z2) local plane_theta2 = get(dr_plane_the2) local plane_phi2 = get(dr_plane_phi2) local plane_psi2 = get(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,setto1) -- Set plane 1 data set(dr_plane_x, plane_x) set(dr_plane_y, plane_y) set(dr_plane_z, plane_z) set(dr_plane_the, plane_theta) set(dr_plane_phi, plane_phi) set(dr_plane_psi, plane_psi) -- Set plane 2 data set(dr_plane_x2, plane_x2) set(dr_plane_y2, plane_y2) set(dr_plane_z2, plane_z2) set(dr_plane_the2, plane_theta2) set(dr_plane_phi2, plane_phi2) set(dr_plane_psi2, plane_psi2) set(dr_override_planepath, setto1) end dataref("gPlaneX", "sim/flightmodel/position/local_x") dataref("gPlaneY", "sim/flightmodel/position/local_y") dataref("gPlaneZ", "sim/flightmodel/position/local_z") dataref("gPlaneTheta", "sim/flightmodel/position/theta") dataref("gPlanePhi", "sim/flightmodel/position/phi") dataref("gPlanePsi", "sim/flightmodel/position/psi") -- Function to update aircraft positions function updateAircraft() local x = get(gPlaneX) local y = get(gPlaneY) local z = get(gPlaneZ) local theta = get(gPlaneTheta) local phi = get(gPlanePhi) local psi = get(gPlanePsi) local plane_x = x + 50 local plane_y = y local plane_z = z + 50 local plane_theta = theta local plane_phi = phi local plane_psi = psi local plane_x2 = x - 50 local plane_y2 = y local plane_z2 = z - 50 local plane_theta2 = theta local plane_phi2 = phi local plane_psi2 = psi local setto1 = 1 -- Enable plane path override --setOverridePlanePath(1) -- 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,setto1) -- Disable plane path override after setting values (optional) -- setOverridePlanePath(0) end -- Update aircraft every frame do_every_frame("updateAircraft()") Edited September 16, 20241 yr by Ahmet Ali
September 16, 20241 yr 1 hour ago, Ahmet Ali said: dataref("dr_plane_x", "sim/multiplayer/position/plane1_x") This creates the lua variable dr_plane_x rather than plane_x you were using before In the original code, dr_plane_x was a pointer reference which is obsolete using lua, lua has no concept of pointers, in lua "everything is a table". 1 hour ago, Ahmet Ali said: attempt to perform arithmetic on local "x" (a nil value) . that is because x is not defined defined - its nil, the definition in this function: 1 hour ago, Ahmet Ali said: function updateAircraft() local x = get(gPlaneX) should be function updateAircraft() local x = gPlaneX AutoATC Developer
September 16, 20241 yr Author 1 hour ago, mSparks said: This creates the lua variable dr_plane_x rather than plane_x you were using before In the original code, dr_plane_x was a pointer reference which is obsolete using lua, lua has no concept of pointers, in lua "everything is a table". that is because x is not defined defined - its nil, the definition in this function: should be function updateAircraft() local x = gPlaneX I am really confused now ı get error again and error says: lua:4: attempt to call a nil value (global 'dataref') same as this error before lua:4: attempt to call a nil value (global 'XPLMFindDataRef') ı just changed those local x = gPlaneX local y = gPlaneY local z = gPlaneZ local theta = get(gPlaneTheta) local phi = get(gPlanePhi) local psi = get(gPlanePsi)
September 16, 20241 yr 9 minutes ago, Ahmet Ali said: I am really confused now ı get error again and error says: lua:4: attempt to call a nil value (global 'dataref') same as this error before lua:4: attempt to call a nil value (global 'XPLMFindDataRef') then you tried to make it call XPLMFindDataRef... 9 minutes ago, Ahmet Ali said: ı just changed those local x = gPlaneX local y = gPlaneY local z = gPlaneZ local theta = get(gPlaneTheta) local phi = get(gPlanePhi) local psi = get(gPlanePsi) 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 AutoATC Developer
Create an account or sign in to comment