ESAc_matador Posted May 4, 2016 Posted May 4, 2016 Hello guys... I am finnally going ahead doing some steps. I am starting to understand some of the basics fo Lua. I am not a programmer, nothing, zero... so it is being hard!!! My question is. I want to run this code ---- adding radio commands local _path1 = missionCommands.addSubMenu("Ground units", nil) missionCommands.addCommand("Moving",_path1,function() trigger.action.setUserFlag("100",1) end,nil) ---- the resto of the script if trigger.misc.getUserFlag("100")== 1 then trigger.action.outText("it works!!!!", 100) end do trigger.action.setUserFlag("100",0) end I can´t make this to work. But if I make this.... it works! Once = time more 2 = load MIST Once = time more 4 = load script (the radio commands) ---- adding radio commands local _path1 = missionCommands.addSubMenu("Ground units", nil) missionCommands.addCommand("Moving",_path1,function() trigger.action.setUserFlag("100",1) end,nil) Once = lua predicate trigger.misc.getUserFlag("100")== 1 = action load script if trigger.misc.getUserFlag("100")== 1 then trigger.action.outText("it works!!!!", 100) end do trigger.action.setUserFlag("100",0) end How can I make it to use it only in ACTIONS = DO SCRIPT???
FSFIan Posted May 4, 2016 Posted May 4, 2016 (edited) Your script does the following three things in order: 1. Add the radio command that will execute a function that sets the flag 2. Check if the flag is set -- if so, display a message. But the flag is not set because the player has not activated the command yet and the flag defaults to 0. 3. Clear the flag. The second solution sets up an action that is triggered by a Lua predicate. That causes DCS to regularly evaluate the Lua predicate (I think once every second). This means that there will be many "attempts" to display the message, and they all fail, until the user actually uses the command -- at that point, the next check of the flag will succeed, and the message will be displayed. You can simply add the action you want to the function you pass to missionCommands.addCommand: ---- adding radio commands local _path1 = missionCommands.addSubMenu("Ground units", nil) missionCommands.addCommand("Moving",_path1,function() trigger.action.outText("it works!!!!", 100) end,nil) Edited May 4, 2016 by [FSF]Ian DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
Recommended Posts