Modding Help Dynamically add wiring nodes

Discussion in 'Starbound Modding' started by EvgEniRus, Nov 24, 2017.

Tags:
  1. EvgEniRus

    EvgEniRus Void-Bound Voyager

    I am currently trying to create an object that I'd like to have different number of input nodes based on its state (e.g. configured through GUI).
    The following line sorta does the trick (replace last argument with actual node locations):
    Code:
    object.setConfigParameter("inputNodes", { {0, 0}, {-1, -1} })
    However, it has one problem: it requires object reinitialization to take effect, and the only way to do it that I know of is reloading current world.

    So, I'm searching for a way to either trigger object reinitialization at will or to reconfigure wiring nodes without requiring initialization. Any ideas?
     
  2. bk3k

    bk3k Oxygen Tank

    Not sure that's possible really due to the wire system being one of those hard-coded things. It is only going to check at initialization time and I don't think there is a function to make it reinitialize that object. Now I'm not sure exactly what your object is supposed to do exactly, but here might be some alternate options.

    1 - Simply have all the nodes you might need from the start, even as some might be unused by certain states. Certainly this is the simple option.

    2 - Do something similar to what the "craftinganvil" does via object add-ons. That would probably mean the object add-ons would have their own nodes (and might be otherwise invisible). The add-on objects would also have to send scripted entity calls to the base object to inform it about node states.
     
  3. EvgEniRus

    EvgEniRus Void-Bound Voyager

    I did it! Sorta...
    Code:
    function uninit()
      if self.replaceNodes then
        local nodes = config.getParameter("inputNodes")
        nodes[1][1] = -1 - nodes[1][1]  -- Toggle first input node's X coordinate between 0 and -1
        world.placeObject(object.name(), object.position(), object.direction(), {inputNodes = nodes})
      end
    end
    
    function onInteraction(args)
      self.replaceNodes = true
      object.smash(true)
    end
    The object breaks and re-places itself with new nodes. Placing has to be done in uninit() handler, because before that old object still occupies its position, so placing new one fails.

    One thing that remains is to reconnect wires that were attached to old object. I could not find functions that modify wire connections, only those that report currently connected objects.
    This is not necessary in my case as of now, but would be nice overall.
     

Share This Page