Berserk-Games / atom-tabletopsimulator-lua

Tabletop Simulator scripting package for Atom.
Other
36 stars 27 forks source link

Runtime error row numbers are incorrect, unable to jump to line with error #109

Open matstevenson opened 4 years ago

matstevenson commented 4 years ago

Context

I am working on a TTS mod that has a Global.-1.ttslua file and multiple object scripts. In each of these scripts there is only a single #include line, which imports code in that I keep under source control -- similar to the setup in this post.

Issue

When I click on an object in-game that runs some code with a runtime error, the row number in the error message is relative to the concatenated file that has all of the included code in it.

For example, I could have files a.ttslua, b.ttslua, and c.ttslua all with 100 lines each, which are then included in the global script. If the error happened on line 55 of b, the error message would show row 155. If I click on <- Jump to Error, I am brought to the original parent file that includes the subsequent files.

This makes debugging very tedious and time-consuming.

Specific Example

Here is an error message I get clicking on a button in-game. The actual error is trying to call a function on a nil value, just used as an example. Note that no file has over 100 lines.

image

Jumping to the error, I am brought in Atom to a file containing only this:

#include <4PlayerHeroRealms/scripts/ui/Discard Hand p1>

That file contains only this:

#include ../sizes
#include ../messages

function onLoad()
  -- some other code here, but importantly the click function calls ...
  params = {1} -- player
  Global.call("discardActive", params)
end

After some manual investigation, the error is actually in the discardActive function within a file called 4PlayerHeroRealms.ttslua that is included by the global script file. I found this out by copy-pasting the concatenated global script file from the in-game editor to another text editor and looked up the line number 197, which was zone.doSomething() where zone was accidentally nil.

andymeneely commented 4 years ago

Can confirm the frustration with this and add that this part of the original blog entry explaining the feature from 2017 does not work today:

If you are in your Global.-1.ttslua file and type a line number into the Go To Function dialog it is smart enough to know which line you are referring to and take you to it. i.e. even though the program I listed at the top of this post only has 3 lines when I see it in the editor, when TTS says there's a bug on line 4345 I can hit ctrl-g and type 4345, and it will take me to the correct line (opening up the relevant included file if necessary).

If I try this in a mod where #include is working fine, putting a number into Go To Function does nothing.