Facocero Posted March 14, 2022 Posted March 14, 2022 Good evening everyone! I have a problem that I cannot solve, I have the underlying script of an event and I need that, when the event occurs, after a few seconds, I have to send a message through the trigger.action.outText function. I tried to see some examples from the wiki, but I only managed to send the message after 20 seconds from the start of the mission, however, not since I landed. Thanks in advance to those who want to help me Handler = {} function Handler:onEvent(event) if event.id == 4 and event.initiator:getDesc()["category"] == 1 then trigger.action.outText('Landing', 10, false) trigger.action.aoutText('TakeOff', 10 false) --this message, I wish I could send it after 15 seconds. end end
fargo007 Posted March 14, 2022 Posted March 14, 2022 Wrap your outText call inside of a timer.scheduleFunction() with the appropriate delay. Have fun. Don't suck. Kill bad guys. https://discord.gg/blacksharkden/
cfrag Posted March 14, 2022 Posted March 14, 2022 25 minutes ago, Facocero said: after a few seconds, I have to send a message through the trigger.action.outText function Something like this (warning: untested) Handler = {} function Handler:onEvent(event) if event.id == 4 and event.initiator:getDesc()["category"] == 1 then trigger.action.outText('Landing', 10, false) timer.scheduleFunction(Handler.saySomething, {}, timer.getTime() + 15) end end function Handler.saySomething() trigger.action.outText('TakeOff', 10 false) --this message, I wish I could send it after 15 seconds. end 1
Facocero Posted March 14, 2022 Author Posted March 14, 2022 Yes, I tried with timer.scheduleFunction (), but I couldn't, I'm not very familiar with Lua syntax and wiki hint help, I don't find it very comprehensive for me. Unfortunately it is my limit that I am trying to overcome. Thank you for your suggestion 18 minuti fa, fargo007 ha scritto: Wrap your outText call inside of a timer.scheduleFunction() with the appropriate delay. 12 minuti fa, cfrag ha scritto: Something like this (warning: untested) thanks I try
Facocero Posted March 14, 2022 Author Posted March 14, 2022 @cfrag I've tried and it doesn't work, hoping I did it correctly. It doesn't give any errors, it just doesn't perform that function.
toutenglisse Posted March 15, 2022 Posted March 15, 2022 6 hours ago, Facocero said: @cfrag I've tried and it doesn't work, hoping I did it correctly. It doesn't give any errors, it just doesn't perform that function. It just lacks a comma after "10" on second message. 1
Facocero Posted March 15, 2022 Author Posted March 15, 2022 11 ore fa, cfrag ha scritto: Why don't you post the .miz, and we'll have a look Works! Thanks, I was the one who, overwhelmed by a hard day of work, was not concentrated enough and made a very trivial mistake.
Facocero Posted March 15, 2022 Author Posted March 15, 2022 Good evening everyone. I have prepared the entire script that I would need for a mission that I am preparing for two helicopters. While it works, however, anomalies do occur. Granted that not being able to test the mission with a friend, I put a second AI helicopter that lands in a certain trigger to verify the execution of the script. Everything seems to work, but I have the impression that the AI helicopter somehow makes the script haywire (I don't know how to define it) For convenience I enclose the mission for those interested in helping me. I make a clarification for who will try the test mission, if you land the AI helicopter first and then you land, a script error will probably be displayed for the AI helicopter and therefore everything works regularly, with the only oddity, that, returning to the "" start "" trigger, even if not always, the radio is activated, as if some other aircraft that does not exist asked the taxi for authorization. If, on the other hand, you land first, script errors begin to appear which, however, I take ok, continues to work even if incomplete. I mean, I've been banging my head on it since this morning, but I can't resolve the matter. Thank you test_ev.miz
toutenglisse Posted March 15, 2022 Posted March 15, 2022 (edited) 1 hour ago, Facocero said: ... makes the script haywire ... script errors begin to appear... 2 mistakes : 1) trigger "zone 3"/"tom" : you schedule function Handler.move11 while the function's name is Handler.move1 2) using Handler.something as function name seems to cause script errors (function seems to call event handler and so parameters are missing). I made corrections to these points in attached miz. test_ev.miz Edited March 15, 2022 by toutenglisse
Facocero Posted March 15, 2022 Author Posted March 15, 2022 8 minuti fa, toutenglisse ha scritto: 2 errori: 1) trigger "zona 3"/"tom": si pianifica la funzione Handler.move11 mentre il nome della funzione è Handler.move1 Thanks for your help. In reality that error is due to a typographical error, because I had to extract only the part that concerned the errors and left out many other things that had nothing to do with the scripts in question.
Facocero Posted March 19, 2022 Author Posted March 19, 2022 (edited) good afternoon everybody. I come back to this topic again because, although everything worked great, thanks to your help, now I ran into another problem, which my inability cannot solve. Basically I would like a string to be displayed after 10 seconds in a simple if then loop. Be patient, I am trying to learn in small steps. Thank you local flag_val = trigger.misc.getUserFlag("9") if flag_val == 1 then trigger.action.outText(" First msg", 5, false) timer.scheduleFunction(_msg,{}, timer.getTime() +5) end fuction (_msg) trigger.action.outText("Second msg" , 5, false) end Edited March 19, 2022 by Facocero
cfrag Posted March 19, 2022 Posted March 19, 2022 It looks to me like you are already 99% where you want to be, but you are currently impeded by some lack of "formal" Lua knowledge - you seem to be piecing everything together just fine, but seem to you lack some important 'big picture' items: how Lua works in principle, how the various pieces fit together. If you knew just a bit more of that, everything would go much smoother for you. Learning Lua inside DCS is a masochistic proposition: it's slow and hurts a lot. I recommend that you look at some of the (very nice) Lua tutorials that show you how to program functions and use variables without having to constantly starting and stopping a DCS mission. It'll probably take you a morning, but after that you can do so much more with much less resistance from DCS. Your current Issue is with your understanding of function (_msg) but you would run straight into the next issue if I merely fixed that for you. Just trust me when I say that you are almost there
Facocero Posted March 19, 2022 Author Posted March 19, 2022 Thanks for the suggestion, I try, but I doubt that following the tutorials, assuming you find the right one and especially in my language, will be able to fully understand this Lua. Among other things, I'm not even a kid anymore, it's difficult for things to stay in my head. Anyway thanks anyway, very kind as always. Regards
Facocero Posted March 20, 2022 Author Posted March 20, 2022 Happy Sunday everyone. Sorry cfrag, I've been trying to understand what I meant by your post in quotas since yesterday. Then I finally got it, maybe you were referring to the way I used to write the function call? ie Function (_msg)? IF yeah well it was my transcription mistake. I had to rename a few entries they were in my language, so editing made it confusing. And most likely I expressed myself badly in the previous post. My question was to understand why putting that exact same code inside an event works, lies inside if .... Then ... no! In the meantime I am reading a lot of tutorials regarding the functions, but I don't see the light yet, at least for this specific problem. 21 ore fa, cfrag ha scritto: Your current Issue is with your understanding of function (_msg) --incorrect fuction _msg() --correct but you would run straight into the next issue if I merely fixed that for you. Just trust me when I say that you are almost there
Facocero Posted March 21, 2022 Author Posted March 21, 2022 Good morning everyone. I solved it, simply by placing the function above before the if. now, just a curiosity, could i know if two identical events can coexist within a given trigger? Example: helicopter base. I land, the landig event is triggered and some things happen (mostly text messages), take off I go on a mission, when I return to base, in the new landig event, it will have to show other messages. I tried to insert two scripts for the same event with different messages, but the moment the event occurs, all the messages including the previous ones are displayed.
toutenglisse Posted March 21, 2022 Posted March 21, 2022 (edited) 54 minutes ago, Facocero said: Good morning everyone. I solved it, simply by placing the function above before the if. now, just a curiosity, could i know if two identical events can coexist within a given trigger? Example: helicopter base. I land, the landig event is triggered and some things happen (mostly text messages), take off I go on a mission, when I return to base, in the new landig event, it will have to show other messages. I tried to insert two scripts for the same event with different messages, but the moment the event occurs, all the messages including the previous ones are displayed. When your script is doing an action calling an external function, be sure that the function has been loaded in script before or it still doesn't exist. For landing event doing different things for 1st or 2nd landing, you can just use increment of a value. Before event part of script, use ex : landingNum = 0, then inside landing event script use : landingNum = landingNum + 1, and then if landingNum == 1 do this message / elseif landingNum == 2 do this other message etc ... Edited March 21, 2022 by toutenglisse
Facocero Posted March 21, 2022 Author Posted March 21, 2022 Thanks @toutenglisse, it was more or less what I was already doing. I was already trying but definitely wrong.
Recommended Posts