Modding Help Adding to a consumable object's item aging scripts

Discussion in 'Starbound Modding' started by Alocer, Aug 5, 2016.

  1. Alocer

    Alocer Scruffy Nerf-Herder

    Some quick background to understand my issue, I've been looking into ways of making my mod, Rot Inventory Icons, universally compatible with other mods. I was altering two scripts for consumable objects, the build and item aging scripts. Looking at any *.consumable file you'll see:
    Code:
    "builder" : "/items/buildscripts/buildfood.lua",
    "itemAgingScripts" : ["/scripts/items/rotting.lua"],
    I realized I don't really need to modify the build script so I removed that part from my *.consumable.patch file. Then as you can see, the itemAgingScripts property is an array instead of just a string liked the builder property. I thought maybe if I could add a second aging script to the itemAgingScripts array instead of replacing the existing 'rotting.lua' script then all of my problems would be solved.

    So that's where my issue lies, I'm not sure if it's an oversight that the property value is an array instead of just a single string or if I just can't get it to use two scripts properly. If my new second script has the same function:
    Code:
    function ageItem(baseItem, aging)
    then as you'd expect it just overwrites the function in 'rotting.lua' defeating the purpose of a second script. If I rename the function, then it doesn't seem to get called at all. Which I guess also makes sense because whatever's calling the function 'ageItem', how would it know to call my function. My new function in my new script just being added to the array doesn't seem to be enough. I haven't tried messing with the parameters at all, I've just tried it as something like:
    Code:
    function ageItemRI(baseItem, aging)
    Any ideas?
     
  2. Nirrudn

    Nirrudn Void-Bound Voyager

    I can't test this since I'm at work, but I think you can just re-define the original ageItem function and reference it within your new one. Something like this:

    Code:
    require "/scripts/items/rotting.lua"
    
    baseRot = ageItem
    
    function ageItem(baseItem, aging)
       ... --Your code here
       baseRot(baseItem, aging) --Trigger the normal rotting behavior
    end
    
     
  3. Alocer

    Alocer Scruffy Nerf-Herder

    Amazing, I had no idea you could assign functions to variables in Lua. That's really cool! Your suggestion worked perfectly, thanks for the help and teaching me something new.
     
  4. Nirrudn

    Nirrudn Void-Bound Voyager

    That's one of the great things about LUA. Everything is an object, even functions!
     

Share This Page