Avorion Wiki
Explore
Main Page
All Pages
Interactive Maps
navigation
Main page
Community portal
Recent changes
Random page
Admin noticeboard
Avorion Community
Official forum
Discord
Twitter
Reddit
Facebook
Steam
Gamepedia
Gamepedia support
Report a bad ad
Help Wiki
Contact us
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
FANDOM
Explore
Current Wiki
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Avorion Wiki
356
pages
Explore
Main Page
All Pages
Interactive Maps
navigation
Main page
Community portal
Recent changes
Random page
Admin noticeboard
Avorion Community
Official forum
Discord
Twitter
Reddit
Facebook
Steam
Gamepedia
Gamepedia support
Report a bad ad
Help Wiki
Contact us
Editing
Debugging Scripts
Back to page
Edit
VisualEditor
View history
Talk (0)
Edit Page
Debugging Scripts
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Lua scripts that run in Avorion rely heavily on the Avorion [[Scripting API]] and thus aren't easy to debug in normal lua environments. Avorion provides a range of methods you can use to debug them more easily though. == '~dev' debug Script == You can add the debug script to your current craft by using the following chat command: <source lang="lua"> /run Entity():addScript("lib/entitydbg.lua") </source> This adds a new '''~dev''' interaction to that entity which opens a large menu that allows you to '''manipulate nearly everything in the sector and your inventory''', and, most importantly: It allows you to '''view and modify variables and scripts of entities, players, sectors''' and so on. This script is meant to ease development and debugging of mods in general, so use it! == Inspect tracebacks == You can inspect server side tracebacks in the server log. On windows, logs are located at %AppData%\Avorion\galaxies\<name-of-save>. == 'print' debugging == An easy way to debug scripts is to add regular calls to <code>print()</code> or <code>eprint()</code> while writing your script. You can open the in-game console with a button. '''Note:''' The in-game console isn't configured to a working button by default, you will have to configure it manually yourself. * <code>print()</code> will print regular output to the console * <code>eprint()</code> will print error output to the console Depending on where the function was executed, the output will have different colors in the console, making it easy to distinguish client-prints from server-prints. Please consult the [[Scripting API]] for more information to these functions. === Advanced print debugging === You can set up a function in a script where you can easily toggle print debugging on and off, which will allow you to leave your 'print' statements in the mod. You would want it to look something like this: <source lang="lua"> local _Debug = 0 function myFunc1(_Arg1) debugPrint("Entering myFunc1 - _Arg1 is " .. tostring(_Arg1)) return _Arg1 + 5 end function debugPrint(_Msg) if _Debug == 1 then print(_Msg) end end </source> This would print "Entering myFunc1 - _Arg1 is 5" if you ran myFunc1(5) somewhere in your script, but only if you set _Debug to 1. Using this, you can toggle debug information on and off whenever you want. === printTable() === Use the <code>printTable()</code> function to recursively print a table. It's defined in '''data/scripts/lib/utility.lua'''. === Logging === Another easy way to debug scripts, mostly while they're being used by players already, is to use logging. You can use the <code>printlog()</code> function, that behaves similarly to <code>print()</code>, but prints to the logfile instead of the console. Depending on whether that function is called on the client or server, it will print to the client or server logfile. == type() == Use <code>type()</code> to find out what kind of object you're dealing with. <code>type()</code> is a built-in lua function that can display the type of an object. <source lang="lua"> local a = 2 local b = "foo" print (type(a)) print (type(b)) </source> Output: number string '''Note:''' <code>type()</code> will always display <code>userobject</code> for Avorion Scripting API objects. See <code>__avoriontype</code> below. == __avoriontype == All Avorion [[Scripting API]] objects have a "secret" <code>__avoriontype</code> property, that is basically just a string containing their internal avorion type. You can use this property to easily * find out if the instance is a Scripting API object * find out what type the object has exactly <source lang="lua"> local m = Matrix() print (type(m)) print (m.__avoriontype) </source> Output: userobject Matrix == /devmode == When typing in the command <code>/devmode</code>, the game goes into development mode. In order for development mode to be properly initialized, a restart is required. The following functionality is only available in /devmode and not meant to be user-friendly in any way. Its only purpose is to speed up development. === entitydbg.lua on each entity === In /devmode, each Entity that can have scripts, will have the ''entitydbg.lua'' script attached to it. === F5 / F6 === Please note: This feature is not polished in any way and can (will...) crash the game on occasion. * F5: Reload scripts of selected Entity (if any) * F5: Reload scripts of current Sector (if no Entity selected) * Shift-F5: Reload scripts of Player * Ctrl-F5: Reload scripts of Sector and all Entities * F6: Clear scripts cache of all client-side scripts (mod files, tooltips, parts, upgrades, sectorspecs, fighter templates) * Ctrl-F6: In addition to normal F6, also reload shaders, textures and client config (this might crash the client if done too often) * Shift-F7: Cycle through various background rendering variations and textures * F11: Reload volumes.ini == Pitfalls == Sadly, the Avorion [[Scripting API]] and its environment comes with a few [[Modding Pitfalls|pitfalls]] that you simply have to be aware of to avoid them. You can read more about [[Modding Pitfalls|Modding Pitfalls here]]. == See Also == * [[Modding Pitfalls]] * [[Best Practices]] * [[Writing your own Mod]] * [[Scripting API]] * [[Avorion Internal Architecture]] * [[Performance Optimization]] [[Category:Modding]]
Summary:
Please note that all contributions to the Avorion Wiki are considered to be released under the CC BY-SA 3.0
Cancel
Editing help
(opens in new window)
Follow on IG
TikTok
Join Fan Lab