Page 1 of 1

[15.34]Error printing tables. Repeatable. Any mods. Any save

Posted: Wed Oct 18, 2017 12:08 am
by Bigfootmech
Also in 15.37 and 15.XX.

1. What did you do?
- Open console
- type (or paste) /c game.player.print(game.player)
- press enter
Bug is repeatable every time.
2. What happened?
Message displayed "Cannot execute command. Error: LuaPlayer doesn't contain key x. stack traceback: [C]: in function 'print' [string "game.player.print(game.player)"]:1:in main chunk
3. What did you expect to happen instead? It might be obvious to you, but do it anyway!
Message containing table: 0x00000000XXXXXXXX (lua behaviour), or printing of some info related to the object, such as type, or its contents.
4. Assumption
Someone made the print command try to print the "position" instead of a table
5. Investigation
With a blueprint in hand (with at least one entity), sending
/c game.player.print(game.player.cursor_stack.get_blueprint_entities()[1].position)
sides with the guess, as it prints {x = ..., y = ...}
6. Possible solution?
Recursively print tables

local function to_string(source)
if type(source) ~= "table" then return tostring(source) end -- tostring here accounts for userdata
local stringy = "{"
for k, v in pairs(source) do
stringy = stringy .. to_string(k) .. " = " .. to_string(v) .. ","
end
stringy = stringy:sub(1,-2) .. "}"

return stringy
end

Provide Attachments:
- log files X 3: Factorio 15.34, 15.37, and 15.XX (37) - with username scratched out for privacy
- save files: none necessary. Works on every save, or newly generated world (tested on multiple new worlds/saves).
- mods folder: unnecesary. Works with and without mods (tested).
- desync-report:none. Local used.
- Screenshots X 4

Re: [15.34]Error printing tables. Repeatable. Any mods. Any save

Posted: Wed Oct 18, 2017 1:27 am
by eradicator
Use /c game.player.print(serpent.line(game.player, {comment = false})) instead. I guess you're right about that it still shouldn't throw an error though.

Edit: Corrected typo in command.

Re: [15.34]Error printing tables. Repeatable. Any mods. Any save

Posted: Wed Oct 18, 2017 1:51 am
by Rseding91
Thanks for the report. I've changed it so it won't give that specific error - but it's still going to error and state that you can't print LuaObjects. Additionally tables aren't printable unless you convert them into a string first.

Re: [15.34]Error printing tables. Repeatable. Any mods. Any save

Posted: Wed Oct 18, 2017 4:20 am
by Bigfootmech
@eradicator
Tried the command, but it didn't work off the bat. I've seen serpent, but couldn't make heads or tails of it (maybe it's an ouroboros). Any case, I've read other stuff to the effect of "don't rely on player being static" or something. So I'm working with that. I also have a... let's say interesting library written now. It makes lua a lot more statically typed >.<

@Rseding91
Awesome! Thank you :D

Re: [15.34]Error printing tables. Repeatable. Any mods. Any save

Posted: Wed Oct 18, 2017 8:33 am
by eradicator
Bigfootmech wrote:@eradicator
Tried the command, but it didn't work off the bat. I've seen serpent, but couldn't make heads or tails of it (maybe it's an ouroboros). Any case, I've read other stuff to the effect of "don't rely on player being static" or something. So I'm working with that. I also have a... let's say interesting library written now. It makes lua a lot more statically typed >.<
Oops. One of the brackets was in the wrong place. I edited the above post to the correct version. You won't get much useful out of printing the player object though as it is not a classic lua table. Not sure what you mean with player being non-static. "game.player" is a shortcut that only works on the ingame console and references the LuaPlayer object of whoever typed the command. You can't use it in a mod directly, it's only good for debugging/testing.

Also no clue why you would want to "make lua more statically typed". Performance is an issue so you shouldn't go too far with abstractions. If you need further help making your mod (assuming you are making one :P)... make a post in the modding help forum ^^, in here nobody else would find the posts if they had similar questions.