LUA script console - hint

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
michaelm75au
Posts: 12455
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

LUA script console - hint

Post by michaelm75au »

As well as using this to test your script snippets, leaving this open while testing events with LUA scripting is also useful.
Any print(..) statements you may have in the LAU action/trigger scripts should also print out in this window. This is very helpful when trying to debug why an event's script is not working - print out the variables, unit tables, etc.
However it is also a good idea to try to make the prints a bit verbose; a number on the screen does not say much.
eg: embedding this is in the event - print('MyEvent: random number = ' .. a) - would print out the value of 'a' during the 'MyEvent'.

I would also suggest commenting these lines out [add 2 dashes in front of it --print('MyEvent: random number = ' .. a)] before publishing to stop them from polluting the Console in case the player is also doing some in it.
I find commenting them out rather than deleting them, is more useful, as at some point you may need to go back to the script for some issue.[:D]
Michael
mikmykWS
Posts: 7185
Joined: Tue Mar 22, 2005 4:34 pm

RE: LUA script console - hint

Post by mikmykWS »

Pinned and FAQ'd.
User avatar
michaelm75au
Posts: 12455
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: LUA script console - hint

Post by michaelm75au »

In SR7, some new tools have been added to help with Events.
1. Tool_DumpEvents(): This will dump out the event/trigger/condition/action to a file so they can be visually checked.
2. The Lua script in the Event can be recorded in the Lua history log. This is useful during testing but could be detrimental if it keeps firing during a game. To turn on this logging, run the line '_lua_event=true' in the Script Console and leave the console open. To run off, just run '_lua_event=false'.
Michael
User avatar
michaelm75au
Posts: 12455
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: LUA list of wrapper fields - hint

Post by michaelm75au »

To get a list of fields in a Command Lua wrapper
1. Get an object wrapper (eg unit = ScenEdit_GetUnit())
2. List the properties ( eg print(unit.fields) )
3. Properties consists of (a) name, (b) type of property, and (c) if you set a value for it (eg unit fields = { property_29 = '.damage , LuaTable , False', property_19 = '.dbid , Int32 , False', method_1 = ':delete , System.Void', property_28 = '.loadoutdbid , Object , False', method_2 = ':inArea , System.Boolean, property_9 = '.course , LuaTable , True' ...
-> property_29 : unit.damage is a Lua table and you can't set a value as in unit.damage = {}
-> property_19 : unit.dbid is a number and you can't set a value as in unit.dbid = 12
-> property_28 : unit.loadoutdbid is a generic object and you can't set a value as in unit.loadoutdbid = 1234
-> property_9 : unit.course is a Lua table and you can set a value as in unit.course = {...}
-> method_1 : unit:delete is a Lua method/function and returns nothing
-> method_2 : unit:inArea is a Lua method/function and returns true/false
Michael
User avatar
ClaudeJ
Posts: 754
Joined: Wed Mar 08, 2006 5:38 pm
Location: Bastogne

Re: LUA script console - hint

Post by ClaudeJ »

Hey there,

is the Lua Console supposed to be available outside the Scenario Editor, ie. in normal gameplay?

Cheers
Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz, NVIDIA GeForce GTX 1650 4 Go, Windows 10 64bits, 32 GB RAM, Regional settings = French, Belgium
(Previously known as JanMasters0n)
User avatar
blu3s
Posts: 625
Joined: Fri Jul 08, 2022 9:45 am

Re: LUA script console - hint

Post by blu3s »

No, it's only available in the editor mode.
Post Reply

Return to “Lua Legion”