Page 1 of 1

Determine if item_prototypes attribute is a pointer?

Posted: Fri Mar 10, 2023 1:46 pm
by Plawerth
Is there a way to determine if an attribute in game.item_prototypes is a pointer rather than a static property?

With all Bob's mods loaded, I notice the following endless recursion using the Global Variable Viewer mod:

Code: Select all

game.item_prototypes.diamond-5
    .group.localised_name = "item-group-name.bob-gems"
    .subgroup.group.localised_name = "item-group-name.bob-gems"
    [....]
    .subgroup.group.subgroups.[1].group.subgroups.[1].group.localised_name = "item-group-name.bob-gems"
Image

Re: Determine if item_prototypes attribute is a pointer?

Posted: Mon Mar 13, 2023 10:53 pm
by lyvgbfh
If you tostring a table, you get a memory reference. You could store a list of those as a hacky way to see if you're entering a table you've already seen.

Re: Determine if item_prototypes attribute is a pointer?

Posted: Tue Mar 14, 2023 8:34 pm
by Rseding91
lyvgbfh wrote: Mon Mar 13, 2023 10:53 pm If you tostring a table, you get a memory reference. You could store a list of those as a hacky way to see if you're entering a table you've already seen.
tostring of a table in Factorio Lua will give you '0'; since the address is not deterministic we do not want any mods to have access to it or they will use it wrong and desync.

Re: Determine if item_prototypes attribute is a pointer?

Posted: Tue Mar 14, 2023 8:36 pm
by Rseding91
I do not understand the original question.

Re: Determine if item_prototypes attribute is a pointer?

Posted: Tue Mar 14, 2023 9:53 pm
by robot256
This is a bug in the Global Variable Viewer mod because it naively walks the prototype tree which includes a doubly-linked 2-level tree of LuaGroup objects. The LuaGroup for the subgroup has a reference to the parent group, and the parent has a reference back to the subgroup.

This should be handled by GVV as a special case IMO. Circular references don't appear that often in the API.