AngelRR92 Posted August 31, 2024 Posted August 31, 2024 Hello, I've been struggling with creating and controlling looped functions with F10 commands. I made some basic CCRP and navigation scripts that I want to control ON and OFF from the F10 menu and also overcome the REPETIVE ACTION 1 second update rate and put it up to 2 times per second or whatever. So I guessed that my solution would be calling the pre-saved script with "assert" and put it in a simple timer.schedule funcion that loops the called script each 0.5 seconds. I define my function, tell it to load my script, make it check my control flag from the F10 menu, control condition linked to that specific flag This is what I got, it works but only displays the information once... I think I'm not declaring my function correctly. Thanks in advance, do local function GlonassWP1(Argument) -- Arguments are not into code, only info! local path ='W:\\DCS\\1. Mission Editor\\Su-25A\\SYRIA RUSSIA V00\\' assert(loadfile(path .. "HDG_COURSE_WP1.lua"))() trigger.misc.getUserFlag(GlonassWP1 ) if trigger.misc.getUserFlag(flagNameWP ) == 1 then timer.scheduleFunction(GlonassWP1, {1}, timer.getTime() + 0.5) -- Reschedule the function to run again after 0.5 sec end end timer.scheduleFunction(GlonassWP1, {}, timer.getTime() + 1) -- Loop will start at start condition +1 secs end
cfrag Posted September 1, 2024 Posted September 1, 2024 (edited) 12 hours ago, AngelRR92 said: it works but only displays the information once... I think the best approach would be to walk through the code and explain why you would expect it to invoked more than once -- that usually helps me. Below I've taken your code, slightly simplified and formatted it for my legibility -- do removed local function GlonassWP1(Argument) -- Arguments are not into code, only info! local path ='W:\\DCS\\1. Mission Editor\\Su-25A\\SYRIA RUSSIA V00\\HDG_COURSE_WP1.lua' assert(loadfile(path))() trigger.misc.getUserFlag(GlonassWP1) -- <-- what do you believe that this line does? if trigger.misc.getUserFlag(flagNameWP) == 1 then -- <--where is flagNameWP defined and set? timer.scheduleFunction(GlonassWP1, {1}, timer.getTime() + 0.5) -- Reschedule the function to run again after 0.5 sec end end timer.scheduleFunction(GlonassWP1, {}, timer.getTime() + 1) -- Loop will start at start condition +1 secs --(missing 'end' to conclude do here, leading 'do' removed) Frankly, I'm slightly surprised that above executed even once, there's a missing 'end' to 'do' that I think Lua glosses over by not enforcing it for do..end. So, you invoke a timed GlonassWP1 once, one second in the future. It runs, and then terminates, just like the code suggests it does. There are two questions: trigger.misc.getUserFlag(GlonassWP1) What is your intended behavior with this? It immediately reads the value of the flag that has the same designation as the address of the table entry for the local function GlonassWP1 that you defined above, returning the number 0. It does not invoke the function. trigger.misc.getUserFlag(flagNameWP) Where do you set the value for global "flagNameWP" that is read? If it is undefined, the value that is returned is the number 0 Edited September 1, 2024 by cfrag
AKA_Clutter Posted September 2, 2024 Posted September 2, 2024 (edited) EDITED - I see I was WAY off base. I'll be interested in what the actual solution is. Edited September 2, 2024 by AKA_Clutter Missed the boat by a mile. ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
AngelRR92 Posted September 2, 2024 Author Posted September 2, 2024 En 1/9/2024 a las 10:30, cfrag dijo: I think the best approach would be to walk through the code and explain why you would expect it to invoked more than once -- that usually helps me. Below I've taken your code, slightly simplified and formatted it for my legibility -- do removed local function GlonassWP1(Argument) -- Arguments are not into code, only info! local path ='W:\\DCS\\1. Mission Editor\\Su-25A\\SYRIA RUSSIA V00\\HDG_COURSE_WP1.lua' assert(loadfile(path))() trigger.misc.getUserFlag(GlonassWP1) -- <-- what do you believe that this line does? if trigger.misc.getUserFlag(flagNameWP) == 1 then -- <--where is flagNameWP defined and set? timer.scheduleFunction(GlonassWP1, {1}, timer.getTime() + 0.5) -- Reschedule the function to run again after 0.5 sec end end timer.scheduleFunction(GlonassWP1, {}, timer.getTime() + 1) -- Loop will start at start condition +1 secs --(missing 'end' to conclude do here, leading 'do' removed) Frankly, I'm slightly surprised that above executed even once, there's a missing 'end' to 'do' that I think Lua glosses over by not enforcing it for do..end. So, you invoke a timed GlonassWP1 once, one second in the future. It runs, and then terminates, just like the code suggests it does. There are two questions: trigger.misc.getUserFlag(GlonassWP1) What is your intended behavior with this? It immediately reads the value of the flag that has the same designation as the address of the table entry for the local function GlonassWP1 that you defined above, returning the number 0. It does not invoke the function. trigger.misc.getUserFlag(flagNameWP) Where do you set the value for global "flagNameWP" that is read? If it is undefined, the value that is returned is the number 0 Thank you for your time, I was calling a flag that acts as trigger for this script. I found this example structure here https://wiki.hoggitworld.com/view/DCS_func_setPoint to replicate and fiddle with: The following will create a laser point and update the point of the ray every half a second. Once the target unit is destroyed it will remove the laser. local jtac = Unit.getByName('jtacBob') local target = Unit.getByName('BMPAirDefenseSystemGroup1_unit1') local ray = Spot.createLaser(jtac, {x = 0, y = 1, z = 0}, target:getPoint(), 1337) local function updateRay() if Object.isExist(target) then ray:setPoint(target:getPoint()) timer.scheduleFunction(updateRay, {}, timer.getTime() + 0.5) else ray:destroy() end end timer.scheduleFunction(updateRay, {}, timer.getTime() + 0.5)
cfrag Posted September 2, 2024 Posted September 2, 2024 (edited) 1 hour ago, AngelRR92 said: I was calling a flag that acts as trigger for this script. Understood. You can't "call flags", though. Flags are merely memory locations that contain a number value. There is no method that gets implicitly invoked if/when a flag's value changes, you have to poll flag values yourself. Edited September 2, 2024 by cfrag
Recommended Posts