Determine if item_prototypes attribute is a pointer?

Place to get help with not working mods / modding interface.
Post Reply
Plawerth
Fast Inserter
Fast Inserter
Posts: 116
Joined: Thu Mar 02, 2017 12:57 am
Contact:

Determine if item_prototypes attribute is a pointer?

Post 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

lyvgbfh
Fast Inserter
Fast Inserter
Posts: 165
Joined: Fri Jul 10, 2020 6:48 pm
Contact:

Re: Determine if item_prototypes attribute is a pointer?

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13202
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Determine if item_prototypes attribute is a pointer?

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13202
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Determine if item_prototypes attribute is a pointer?

Post by Rseding91 »

I do not understand the original question.
If you want to get ahold of me I'm almost always on Discord.

robot256
Filter Inserter
Filter Inserter
Posts: 596
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Determine if item_prototypes attribute is a pointer?

Post 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.

Post Reply

Return to “Modding help”