Page 1 of 1

Lua questions

Posted: Fri Dec 19, 2014 6:16 pm
by mx1
Lua is a great addtion to CMANO, thanks again to developers for this feature. Now I have a couple of questions:
1. How to use UnitX feature? I've setup a trigger "unit remains in area" and added Lua script action. The event is fired and so is the script, but I don't know how to use UnitX to get to the unit that triggered event. I've tried:

Code: Select all

 my_var=UnitX
 my_var=ScenEdit_GetUnit({side="A", name=my_var})
 ScenEdit_AddReferencePoint({side="A", name=my_var, latitude="N54.44.42", longitude="E18.48.42"})
 
No luck

Code: Select all

 my_var=UnitX.name
 ScenEdit_AddReferencePoint({side="A", name=my_var, latitude="N54.44.42", longitude="E18.48.42"})
 
No luck either.

2. Is there a way to do some debug printing in actions? print() works in script console, but I don't see output when script is run as action.

RE: Lua questions

Posted: Sat Dec 20, 2014 8:32 pm
by DeSade
1. couldn't get UnitX to work either
2. there is undocumented function ScenEdit_MsgBox('str', style), for example ScenEdit_MsgBox(unit.guid,0). You cant really catch exceptions, but you can use it to test logic and branching

hope that helps a bit :)

RE: Lua questions

Posted: Sat Dec 20, 2014 10:35 pm
by RoryAndersonCDT
UnitX currently only works with ScenEdit_AssignUnitToMission eg:
ScenEdit_AssignUnitToMission ('UnitX','CAP Mission')



Though in the future one will be able to do something akin to: (This is currently not in 1.06)
UnitX().course = {{latitude=0,longitude=0}}
To make unitX set a course for that location.



You are quite right that ScenEdit_MsgBox isn't documented; sorry about that I missed that one while documenting. It should show up in the built-in list of Lua functions in Command.

RE: Lua questions

Posted: Thu Jan 15, 2015 7:31 pm
by mx1
Thanks for insight. MsgBox is quite useful for debugging. Still, any functionality that would indicate at a runtime that there is a problem with a script (syntax, wrong function call etc.) would be very helpful. I know I can run the script in console but not all errors can be found this way. It would be also helpful if the scripting console had line numbering - right now "error at line 52" is quite hard to spot.

I have one more feature request:

"The unit enters zone" trigger can only be precisely defined for the units already in the scenario. If the unit is added via Lua script, then it is not possible to refer to it in trigger. It would be useful to have such functionality. My use case is that I deploy RHIBs using Lua and then deploy special forces from them when they are close to the beach. My current workaround is to have trigger enabled by any unit belonging to the class ('surface ship' in my case). If at least we can identify which unit triggered the event (which relates to the UnitX functionality) it would simplify code a lot.