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

This subforum contains all the issues which we already resolved.
User avatar
Bigfootmech
Burner Inserter
Burner Inserter
Posts: 18
Joined: Wed Oct 11, 2017 8:06 pm
Contact:

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

Post 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
Attachments
factorio-15.XX.log
(3.77 KiB) Downloaded 96 times
game.player.print(game.player.cursor_stack.get_blueprint_entities()[1].position) with blueprint in hand
game.player.print(game.player.cursor_stack.get_blueprint_entities()[1].position) with blueprint in hand
experimental_print_long.png (3.71 MiB) Viewed 1879 times
game.player.print(game.player)
game.player.print(game.player)
experimental_print.png (3.94 MiB) Viewed 1879 times
print_long.png
print_long.png (3.21 MiB) Viewed 1879 times
print player.png
print player.png (3.16 MiB) Viewed 1879 times
factorio-15.37.log
(18.39 KiB) Downloaded 94 times
factorio-15.34.log
(4.47 KiB) Downloaded 96 times
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.
Last edited by eradicator on Wed Oct 18, 2017 8:27 am, edited 1 time in total.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14269
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Bigfootmech
Burner Inserter
Burner Inserter
Posts: 18
Joined: Wed Oct 11, 2017 8:06 pm
Contact:

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

Post 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
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Post Reply

Return to “Resolved Problems and Bugs”