Page 1 of 1

LUA script console - hint

Posted: Sun May 22, 2016 4:04 am
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]

RE: LUA script console - hint

Posted: Tue May 24, 2016 12:44 pm
by mikmykWS
Pinned and FAQ'd.

RE: LUA script console - hint

Posted: Sat Feb 11, 2017 9:55 pm
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'.

RE: LUA list of wrapper fields - hint

Posted: Sat Mar 24, 2018 1:20 pm
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

Re: LUA script console - hint

Posted: Tue Nov 21, 2023 1:45 am
by ClaudeJ
Hey there,

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

Cheers

Re: LUA script console - hint

Posted: Tue Nov 21, 2023 12:03 pm
by blu3s
No, it's only available in the editor mode.