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?
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 PHP: object.setConfigParameter("charges", 50) Other script (or object script) PHP: local count = world.getObjectParameter(objectId, "charges", 0) Here's a couple of vanilla scripts that make use of the function: Code: /objects/crafting/upgradeablecraftingobjects/upgradeablecraftingobject.lua /objects/fossils/dirtyfossils/dirtyfossil.lua /objects/fossils/displaystands/fossildisplay.lua /objects/microformer/microformer.lua /objects/protectorate/objects/protectoratebeamaxe/protectoratebeamaxe.lua
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: Code: "physicsCollisions" : { "barrierVertical" : { "collision" : [ [-0.25, 0], [0.25, 0], [0.25, 5], [-0.25, 5] ] } }
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.
It seems to work the same as config.getParameter does. IIRC you can do something like Code: config.getParameter("myTable.nested") 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. Code: 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 end end update_collisions = function() storage.matSpaces = buildMaterialSpaces(storage.collisions, "metamaterial:objectsolid") object.setMaterialSpaces(storage.matSpaces) end clear_collisions = function() object.setMaterialSpaces({}) end restore_collisions = function() object.setMaterialSpaces(storage.matSpaces) end buildMaterialSpaces = function(spaces, material) local retTable = {} for i, space in ipairs(spaces) do retTable[i] = {space, material} end return retTable end 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.
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: config.getParameter("physicsCollisions")["barrierVertical"]["collision"][1][2] 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 )