Scripting Reference?

User avatar
pvajko
Posts: 11
Joined: Mon Jan 30, 2017 2:57 am

Re: Scripting Reference?

Post by pvajko » Mon Jan 30, 2017 4:13 am

JupAxe wrote: so I created my first mod which added a bunch of console commands to help me debug and inspect the LUA code.
How exactly are you debugging and inspecting Lua code from the console?

Just joined this forum, enjoyed playing FS15 and 17. Started using more realistic maps like Coldborogh Park with irregularly shaped fields, also with Courseplay and not happy how it generates the field work pattern so looked at the code and I think I could improve it a bit.

Was wondering what development environment people are using when working with Lua scripts. For example is there any way to force reload a script without quitting the game? When trying minor changes I found that Courseplay reloads only when a new game is started and since I'm not familiar with Lua I wish there was a way to catch syntax errors earlier.

User avatar
Decker_MMIV
Posts: 237
Joined: Wed Aug 22, 2012 1:02 am

Re: Scripting Reference?

Post by Decker_MMIV » Mon Jan 30, 2017 6:07 pm

pvajko wrote:[..] what development environment people are using [..]
I'm using Notepad++ or Visual Studio Code for editing LUA-script and I3D/XML files.

Unfortunately there does not seem to be any way of when-in-a-game-session reloading a changed LUA-script, so I usually keep a "fast loading" savegame slot containing just the very few mods needed to test LUA-script changes.

If a script change does not work, and it is possible to quit the current game-session to go back to main-menu, I do that. - Or if something went very wrong, where the in-game console is still operational, I issue a 'quit' (or 'q') command to completely shutdown the FS17 application.

I know of no actual debugger build into FS17 (other that the profiler screens, key F8), so whatever you need to "debug", you have to make yourself - either by poor-mans debugging; which is print'ing the variables/objects you need to keep track of/examine, or otherwise render text/graphics onto the screen.

And it should go without saying, that; always check the LOG.TXT file, even when being in-game. - Having a 2-monitor setup helps a bit here.

It is possible to register 'your own' console commands, and thereby control your mod with those - again something you do yourself in your own code.

With the new LUADOC documentation, there seems to be only one non-obvious example of how to register a custom console-command, in PowerConsumer:load() line 53. - Via Google searching for "addConsoleCommand site:gdn.giants-software.com" I found this old topic in the GDN-forum regarding addConsoleCommand()

User avatar
pvajko
Posts: 11
Joined: Mon Jan 30, 2017 2:57 am

Re: Scripting Reference?

Post by pvajko » Tue Jan 31, 2017 3:22 am

Thanks for all the links, I'll check them out, custom console commands seem to be very useful.
Decker_MMIV wrote:always check the LOG.TXT file, even when being in-game
I tried tailing it from a bash shell but seemed like they don't flush it too often...
The in-game console is great, my only problem with that was it cuts the longer lines and some of the error messages aren't fully visible. Is there any way to wrap lines in there or scroll or make the font smaller?

User avatar
Decker_MMIV
Posts: 237
Joined: Wed Aug 22, 2012 1:02 am

Re: Scripting Reference?

Post by Decker_MMIV » Tue Jan 31, 2017 4:58 pm

Using Notepad++'s tail implementation (View -> Monitoring) for me the LOG.TXT is flushed often enough.

I do not know of any way to make the in-game console's font smaller, nor wrap lines.

JupAxe
Posts: 19
Joined: Thu Nov 24, 2016 10:04 am

Re: Scripting Reference?

Post by JupAxe » Thu Feb 02, 2017 7:55 pm

Yeah, the development environment I used was also quite limited and very similar to what is mentioned above -- it consisted of Notepad++, Tail for Win32, and some LUA utility functions I created with the "addConsoleCommand." Debugging consisted of using the built in debug functions (DebugUtil and the General Engine functions) -- but mostly just liberal use of "print."

Notepad++ has syntax checking for both LUA and XML. Tail for Win32 because of the limitations of the in game console. And then I just restarted/reloaded the game when needed - which was a lot. It is not the fastest process and somewhat aggravating when you are used to better development environments.

It would be interesting to get some feedback from the developers of courseplay (which is a bit larger code base) to see if they use anything more sophisticated for LUA development and testing.

User avatar
pvajko
Posts: 11
Joined: Mon Jan 30, 2017 2:57 am

Re: Scripting Reference?

Post by pvajko » Mon Nov 06, 2017 2:29 pm

To follow up on the development environment, I ended up with IntelliJ Idea with the Lua plug-in which does a great job finding syntax and other errors with the code analysis (and also has a vim plugin:). For tail, I use the Windows Powershell's Get-Content -Wait, which seems to work just fine.

I keep the course generation code encapsulated so it can run outside of the game environment. This is allows for easy debugging and (automated) testing but unfortunately I don't have access to the engine's functions (like the scenegraph local/world translations).

I was wondering if anyone tried using the editor to load a map and testing scripts from within the editor, I made an attempt and it works with a single file but could not figure out how to load (source, require, whatever) external modules easily.

User avatar
pvajko
Posts: 11
Joined: Mon Jan 30, 2017 2:57 am

Re: Scripting Reference?

Post by pvajko » Mon Nov 06, 2017 2:31 pm

Also, since I saw here update and updateTick mentioned earlier, you may probably know the answer for the question I tried in the GDN forum too:

Is there any way to get the real time in a millisecond granularity?

My script was causing the game to hang for a few seconds so I wanted to find out how much time it spends in that function. Tried to use dt from update() but that does not seem to include the time spent in scripts. dt does not change while update() is executing. And at the next call, it does not seem to include the time spent in update, rather it seems to be the time between the last return from update() and the entry to update().

User avatar
Decker_MMIV
Posts: 237
Joined: Wed Aug 22, 2012 1:02 am

Re: Scripting Reference?

Post by Decker_MMIV » Mon Nov 06, 2017 5:33 pm

Try one of these:

Code: Select all

g_currentMission.time  -- not likely, since it is also "just a variable".
getTime()
getTimeSec()           -- best candidate it seems.
netGetTime()
Since `dt` is an argument to `update / updateTick`, it won't change its value when within that method - unless your script-code assigns something to it.

In case you haven't already a suspicion of where - in your own script-code - there is a performance-problem, and the time-functions does not give enough resolution to pin-point it, then you have to "disable" parts of your code, to see if the "disabled"-part suddenly made the game-engine run better/faster than before.

Normally I would say that for-, while- and do-while-loops which iterates through many elements and does something "heavy" on them, would be the first place to examine.

Or if you use some foliage-layer/density-map methods and specify a large area to affect, even if it is "just a method call", then the amount of "foliage layer pixels" that needs to be examined/manipulated can cause quite a slow-down.

User avatar
pvajko
Posts: 11
Joined: Mon Jan 30, 2017 2:57 am

Re: Scripting Reference?

Post by pvajko » Mon Nov 06, 2017 6:40 pm

Thanks for giving it a thought, those you mentioned are one second resolution only.

Sorry I wasn't clear enough, I didn't expect dt to change while my script is executing, what I meant was that the value does not include the time spent in the update call itself.

Also I know exactly what causes the delay, what I wanted was to have a metric of the improvements I made like something needed 600ms runs in 200 after my change.

User avatar
Deekay
Posts: 21
Joined: Sat Nov 17, 2018 6:20 pm

Re: Scripting Reference?

Post by Deekay » Fri Nov 23, 2018 4:05 pm

Hi, any chance to get the script reference for the LS19?
don`t stop learning.. *thumbsup*

User avatar
Eep
Posts: 98
Joined: Mon Nov 26, 2018 6:07 pm

Re: Scripting Reference?

Post by Eep » Thu Dec 06, 2018 8:12 am

Deekay wrote:
Fri Nov 23, 2018 4:05 pm
Hi, any chance to get the script reference for the LS19?
Nothing yet but there's https://github.com/scfmod/fs19_lua

User avatar
Deekay
Posts: 21
Joined: Sat Nov 17, 2018 6:20 pm

Re: Scripting Reference?

Post by Deekay » Fri Dec 07, 2018 8:35 am

Eep wrote:
Thu Dec 06, 2018 8:12 am
Deekay wrote:
Fri Nov 23, 2018 4:05 pm
Hi, any chance to get the script reference for the LS19?
Nothing yet but there's https://github.com/scfmod/fs19_lua


thank you !! :)
don`t stop learning.. *thumbsup*

User avatar
Eep
Posts: 98
Joined: Mon Nov 26, 2018 6:07 pm

Re: Scripting Reference?

Post by Eep » Fri Dec 14, 2018 5:52 pm



Post Reply