Modding Help ipairs - getInputNodeIds

Discussion in 'Starbound Modding' started by The | Suit, Feb 18, 2017.

  1. The | Suit

    The | Suit Agent S. Forum Moderator

    I am at my wits end, on why the ID's are not showing.
    Either there is a bug in the code - or the game.

    You can see the lua snipet and log below.
    You will notice all the log functions are reporting in except the ipairs functions.
    Already confirmed that "x" - is a table.
    But for some reason ipairs refuses to extract the data from the table.

    Test = making sure the function is being called
    True \ False - is me switching the object input node on and off.

    Code:
    function init()
      if storage.state == nil then storage.state = false
      end
    
      if config.getParameter("inputNodes") then
        processWireInput()
      end
    end
    
    function onNodeConnectionChange(args)
      processWireInput()
    end
    
    function onInputNodeChange(args)
      processWireInput()
    end
    
    function processWireInput()
      txlog()
    
      if object.isInputNodeConnected(0) then
        sb.logInfo(tostring(object.getInputNodeLevel(0)))
        storage.state = object.getInputNodeLevel(0)
        world.spawnLiquid(entity.position(), 1, 1)
      end
    
    end
    
    function txlog()
    sb.logInfo("Test")
    x = object.getInputNodeIds(0)
    for i,v in ipairs(x) do
       sb.logInfo(tostring(i) .." Table Spot")
       sb.logInfo(tostring(v).. " Id")
    end
    end
    
    Code:
    [19:46:34.076] [Info] Test
    [19:46:34.076] [Info] false
    [19:46:34.722] [Info] Test
    [19:46:34.722] [Info] true
    [19:46:35.174] [Info] Test
    [19:46:35.174] [Info] false
    [19:46:35.562] [Info] Test
    [19:46:35.562] [Info] true
    
     
  2. nickc01

    nickc01 Phantasmal Quasar

    I had the same problem when dealing with object.getOutputNodeIds, and I"m assuming it's the same deal with getInputNodeIds.

    The function getInputNodeIds can't use ipairs to iterate, because from what I learned, numbered tables that have gaps/holes in them can't be iterated with "ipairs", try using "pairs" instead,
    if you need the "i" to be a number, then use tonumber(i) to convert it from a string to a number.

    btw, for this table, the "i" part should have the object ID in string form, not the "v".
     
    Last edited: Feb 18, 2017
    IHart and The | Suit like this.
  3. The | Suit

    The | Suit Agent S. Forum Moderator

    Thanks - I will give it a try
     
  4. The | Suit

    The | Suit Agent S. Forum Moderator

    You were right, pairs worked fine.
    I was not expecting it to have empty spaces - though it is giving me the wrong entity ID - at least its one stop closer.

    Edit:
    Seems it was giving wrong name - as the function seems to be having issues with multiple inputs in a single node.
    Will need to work out what is going on - but everything is working fine now.

    Thanks for everything.
     
    Last edited: Feb 18, 2017
    nickc01 likes this.
  5. bk3k

    bk3k Oxygen Tank

    If ipairs won't work, the indexes might be like "1" instead of 1. ipairs only works on numeric indexes in sequence.

    I ran a string check for
    object.getInputNodeIds(
    and
    object.getOutputNodeIds(
    to see how it is actually used in game. No matches! Only finding this in mods. Since they aren't used in game, I could see an oversight on the return tables for these functions being missed by any testing. I might look later and see exactly what the keys are and if the structure matches what is described in the docs.

    Note I have found at least one item where the documentation is incorrect regarding the function return. Rather than a table (as documented), it sent back multiple returns(probably more ideal for what it does anyhow). activeItem.aimAngleAndDirection is the function in question.
     

Share This Page