Alex-Berdos Posted April 3 Share Posted April 3 Team Let me know why is this happening >>> and how setup (3) value if I do inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM code works but if I do inst:AddComponent("stackable") inst.components.stackable.maxsize = 3 it goes to = [00:02:27]: [string "scripts/components/stackable_replica.lua"]:99: attempt to perform arithmetic on field '?' (a nil value) LUA ERROR stack traceback: scripts/components/stackable_replica.lua:99 in (method) SetMaxSize (Lua) <98-100> FULL CODE - local assets= { Asset("ANIM","anim/coin.zip"), Asset("ATLAS","images/inventoryimages/coin.xml"), Asset("IMAGE","images/inventoryimages/coin.tex"), } local function fn() local inst=CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("coin") inst.AnimState:SetBuild("coin") inst.AnimState:PlayAnimation("idle") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname="images/inventoryimages/coin.xml" inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM MakeHauntableLaunch(inst) return inst end return Prefab("coin",fn,assets) Link to comment https://forums.kleientertainment.com/forums/topic/170421-short-code-tip-needed/ Share on other sites More sharing options...
Bumber64 Posted April 3 Share Posted April 3 The value is used as an index in a table in stackable_replica.lua. local STACK_SIZES = { TUNING.STACK_SIZE_MEDITEM, TUNING.STACK_SIZE_SMALLITEM, TUNING.STACK_SIZE_LARGEITEM, TUNING.STACK_SIZE_TINYITEM, TUNING.STACK_SIZE_PELLET, } local STACK_SIZE_CODES = table.invert(STACK_SIZES) ... function Stackable:SetMaxSize(maxsize) self._maxsize:set(STACK_SIZE_CODES[maxsize] - 1) end If your value isn't in that table, the function is attempting (nil - 1). Link to comment https://forums.kleientertainment.com/forums/topic/170421-short-code-tip-needed/#findComment-1857622 Share on other sites More sharing options...
Alex-Berdos Posted April 3 Author Share Posted April 3 4 hours ago, Bumber64 said: The value is used as an index in a table in stackable_replica.lua. local STACK_SIZES = { TUNING.STACK_SIZE_MEDITEM, TUNING.STACK_SIZE_SMALLITEM, TUNING.STACK_SIZE_LARGEITEM, TUNING.STACK_SIZE_TINYITEM, TUNING.STACK_SIZE_PELLET, } local STACK_SIZE_CODES = table.invert(STACK_SIZES) ... function Stackable:SetMaxSize(maxsize) self._maxsize:set(STACK_SIZE_CODES[maxsize] - 1) end If your value isn't in that table, the function is attempting (nil - 1). Hey Bumber64, it looks like you give me right way to go, but I`m still fresh in coding, so generally: -should I study more about replica? -should I push stacksize value I want to setup > to global table? -just let me know how to make maxsize = 3, Link to comment https://forums.kleientertainment.com/forums/topic/170421-short-code-tip-needed/#findComment-1857821 Share on other sites More sharing options...
Bumber64 Posted April 4 Share Posted April 4 You'd need to put your value (3) in the STACK_SIZES table. You're going to have to include a modified copy of stackable_replica.lua with your mod (will break in the future if Klei makes their own changes, and you'll need to update your mod) or learn to upvalue hack (kind of complicated). The table looks like it supports a max of 8 entries, because it's sending an index of 0-7 over the network. It seems to be used to support the Elastispacer resizing. Link to comment https://forums.kleientertainment.com/forums/topic/170421-short-code-tip-needed/#findComment-1858155 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now