Modding Help How do you use object.setConfigParameter?

Discussion in 'Starbound Modding' started by Shreddys, Aug 23, 2018.

  1. Shreddys

    Shreddys Phantasmal Quasar

    I know the documentation says: "Sets the specified override configuration parameter for the object." But it doesn't seem to do anything when I try using it.

    Does anyone know of a script I can use as an example?
  2. Errors4l

    Errors4l Spaceman Spiff

    I don't know precisely how much that function can affect the object without any additional scripting, but I do know it can be used to fetch object data from any script.

    Object script
    Other script (or object script)
    local count world.getObjectParameter(objectId"charges"0)
    Here's a couple of vanilla scripts that make use of the function:
    Shreddys likes this.
  3. Shreddys

    Shreddys Phantasmal Quasar

    Thank you. That clears up my question. It doesn't seem to work on nested variables though.
    Do you know of any way to change a nested variable? Like the values in this:
      "physicsCollisions" : {
      "barrierVertical" : {
      "collision" : [
      [-0.25, 0],
      [0.25, 0],
      [0.25, 5],
      [-0.25, 5]
      ]  }  } 
  4. Errors4l

    Errors4l Spaceman Spiff

    You'll probably have to overwrite the entire thing, and that's if the collision can even be changed in this fashion. You can use world.getObjectParameter to get the initial values, adjust those and then use object.setConfigParameter to give it a shot.
  5. bk3k

    bk3k Oxygen Tank

    It seems to work the same as config.getParameter does. IIRC you can do something like
    so I presume you could do the same with object.setConfigParameter.

    If it was collisions you wanted to change, I don't think the engine is going to update that in real time this way because it only looks as the JSON data at certain times. Instead you'd want to use object.setMaterialSpaces() which can place metamaterial tiles - aka what your collisions are anyhow - as you please.
    /objects/wired/door/door.lua is an example of this, although vanilla uses this rather inefficiently. Rebuilding the same table instead of storing it even though doors can't move seems silly to me.

    get_collisions = function()
      storage.collisions = {}
      local pos = entity.position()
      local c = config.getParameter("collision", {})  //default return empty table
      for k, v in ipairs(c) do
        storage.collisions[k] = v + pos
    update_collisions = function()
      storage.matSpaces = buildMaterialSpaces(storage.collisions, "metamaterial:objectsolid")
    clear_collisions = function()
    restore_collisions = function()
    buildMaterialSpaces = function(spaces, material)
      local retTable = {}
      for i, space in ipairs(spaces) do
        retTable[i] = {space, material}
      return retTable
    Then you'd call get_collisions() and update_collisions() in init(), plus calling update_collisions() as needed when things change. Now depending on the project, you might want to save your new collisions between sessions etc. In that case object.setConfigParameter() comes in handy, so you could work it into that code pretty easily.
    Shreddys likes this.
  6. Shreddys

    Shreddys Phantasmal Quasar

    Thank you for the help.

    As a side note, while I was poking around I found the syntax required to return the value of a nested table with config.getParameter(). Turns out it was just sub-tables listed in square brackets after the function, like:

    Now I'm really curious if something similar can be done with the object.setConfigParameter() function. I haven't been able to work out possible syntax for that though. Any ideas?

    Edit: I mean, something more elegant than this:
    local dA = config.getParameter("detectArea")
    dA[1][1] = dA[1][1] - 10
    object.setConfigParameter("detectArea", dA)

    (I just grabbed a table at random, I'm not interested in detectArea itself :( )
    Last edited: Aug 24, 2018

Share This Page