Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Lua in scenario guidelines

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Lua in scenario guidelines Page: [1]
Login
Message << Older Topic   Newer Topic >>
Lua in scenario guidelines - 9/10/2016 4:59:29 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
I have put together a list of items to be aware of when using Lua with Command scenarios.

I hope it is helpful.

Release 1.11.SR7
Note:
Due to how errors are now handle from SR7, if a command fails in the console window, it will show an error. If the command runs outside the console (as in an event script), it will not fail with a visible error but return a nil or "" or some other value.
One issue with commands running in an event is that sometimes they fail with an in-game message that actually stops the rest of the script from running. Now, these event scripts will run without any in-game message showing, and the designer should check the result of the command and handle any error condition, and let the remaining script run as needed.

My intent is have all command errors behave in the same fashion in the console window; and the command errors outside a console behave without stopping the script. Which requires the designer to cater for the specific error conditions. Benefit of showing the error regardless, is that sometimes a real error is hidden by just assuming the command works. A good example is this: assume you have a unit 'My Unit' in game. Running the command 'ScenEdit_GetUnit({name='My Unit '})' would return a nil in the earlier releases. Obviously this is wrong; there is no unit 'My Unit '. Now when you try this in the console, it will show as an error.

To emulate the expected outcome from an event, put 'Tool_EmulateNoConsole(true)' at the start of the script to be tested; it is not required in the event code as the script is already not running in a console.

Note also, that the Lua history log should also record the event script errors.

Hope this makes sense.

Attachment (1)

< Message edited by michaelm -- 2/18/2017 2:33:02 AM >


_____________________________

Michael
Post #: 1
RE: Lua in scenario guidelines - 9/10/2016 5:21:34 AM   
mikmykWS

 

Posts: 11524
Joined: 3/22/2005
Status: offline
We think it's awesome!

_____________________________


(in reply to michaelm75au)
Post #: 2
RE: Lua in scenario guidelines - 9/10/2016 10:57:08 AM   
Rory Noonan

 

Posts: 2816
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
That's a great help, thank you.

(in reply to mikmykWS)
Post #: 3
RE: Lua in scenario guidelines - 9/10/2016 2:02:07 PM   
thewood1

 

Posts: 6529
Joined: 11/27/2005
Status: offline
That is excellent.

(in reply to Rory Noonan)
Post #: 4
RE: Lua in scenario guidelines - 9/10/2016 8:55:12 PM   
mikkey


Posts: 3142
Joined: 2/10/2008
From: Slovakia
Status: offline
Excellent work Michael, thanks!

(in reply to thewood1)
Post #: 5
RE: Lua in scenario guidelines - 9/11/2016 2:05:47 AM   
tjhkkr


Posts: 2428
Joined: 6/3/2010
Status: offline
Thank you very much!

_____________________________

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.

(in reply to mikkey)
Post #: 6
RE: Lua in scenario guidelines - 9/11/2016 2:05:48 AM   
tjhkkr


Posts: 2428
Joined: 6/3/2010
Status: offline
Thank you very much!

_____________________________

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.

(in reply to mikkey)
Post #: 7
RE: Lua in scenario guidelines - 9/11/2016 10:30:55 AM   
Zaslon

 

Posts: 283
Joined: 6/14/2015
Status: offline
Very interesting. Thanks Michael.

_____________________________


Kids think about Iran and Amateurs think about Russia, but professionals think about China

(in reply to tjhkkr)
Post #: 8
RE: Lua in scenario guidelines - 9/11/2016 1:29:59 PM   
kevinkins


Posts: 2257
Joined: 3/8/2006
Status: offline
Welcome addition to the resources. Reminds of the old days when there were sites that contained code snipets and examples in different languages. I'm the type that needs a working example for each element of the code. Thanks for that.

(in reply to Zaslon)
Post #: 9
RE: Lua in scenario guidelines - 2/16/2017 8:40:51 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
Note:
Due to how errors are now handle from SR7, if a command fails in the console window, it will show an error. If the command runs outside the console (as in an event script), it will not fail with a visible error but return a nil or "" or some other value.
One issue with commands running in an event is that sometimes they fail with an in-game message that actually stops the rest of the script from running. Now, these event scripts will run without any in-game message showing, and the designer should check the result of the command and handle any error condition, and let the remaining script run as needed.

My intent is have all command errors behave in the same fashion in the console window; and the command errors outside a console behave without stopping the script. Which requires the designer to cater for the specific error conditions.

To emulate the expected outcome from an event, put 'Tool_EmulateNoConsole(true)' at the start of the script to be tested; it is not required in the event code as the script is already not running in a console.

Note also, that the Lua history log should also record the event script errors.

Hope this makes sense.

_____________________________

Michael

(in reply to kevinkins)
Post #: 10
RE: Lua in scenario guidelines - 2/16/2017 2:51:23 PM   
Randomizer


Posts: 1473
Joined: 6/28/2008
Status: offline
How have I missed this thread for months? D'oh! And by the way Michaelm, many thanks for all you do in ridding the community of fear and ignorance wherever Lua meets CMANO.

-C

(in reply to michaelm75au)
Post #: 11
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Lua in scenario guidelines Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.687