Jump to content

Recommended Posts

 I want to pay attention that the order that items are returned is not defined in pairs function. I'm not sure if it's important (e.g. for initializing EQUIPSLOT_IDS in constnts.lua and equippable_replica.lua).

I mean that modders have to do the same thing. And order may change after adding new items to EQUIPSLOTS table. May be it's ok for now. But as I said officially order is not defined so it's a little risk.

I think it's better to make indexed table as main table.
 

Edited by Maris

It seems to me, that the implementation of pairs is stable. By that I mean that it returns the items in the same order if the source table is the same. Otherwise things like this in prefab/player_classified.lua would fail fairly quickly when run on the server vs. the client:

for k, v in pairs(AllRecipes) do
    if IsRecipeValid(v.name) then
        inst.recipes[k] = net_bool(inst.GUID, "builder.recipes["..k.."]", "recipesdirty")
        inst.bufferedbuilds[k] = net_bool(inst.GUID, "builder.buffered_builds["..k.."]", "bufferedbuildsdirty")
    end
end

 

It returns the items in the same order for now. But could it be a source of random rare bugs/crashes in future?

Btw I had some issues after deleting some recipes. For example:

AllRecipes.spear = nil  --all_cleints_require_mod

 

Edited by Maris
  • Developer

Yup, there's some room for error here with mods modifying the tables. There's quite a few areas in our code that relies on the stability of pairs with tables that are identical, mods obviously will affect that, so I'll be looking into complications from this. Thanks!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...