Page 1 of 1

Script Question: Can an object's connections be polled?

Posted: Wed Nov 07, 2012 11:46 am
by Isaac
Does anyone know how (or if) an object's connection targets can be determined via script?

For example: If I wanted to connect three buttons (or 300) to various objects, and connect all of them to one specific script that could detect what [else] the calling button is connected to... Is this possible to do?

Re: Script Question: Can an object's connections be polled?

Posted: Wed Nov 07, 2012 12:48 pm
by 3socks
You could create this functionality by yourself.
Create a function called for example addMyConnector(object, event, target, action) and a table e.g. allConnections, where you will store all connections and connected objects to them.
In addMyConnector call addConnector on object with other parameters passed to this function. And then store what you want to the allConnections table. Use this function in your scripts anytime you want to create a connection.
Then you should have all the data you need in allConnections table.

Something like this:

Code: Select all

allConnections = {}
function addMyConnector(object, event, target, action)
    object:addConnector(event, target, action)
    if allConnections[object.id] == nil
    then
        allConnections[object.id] = {target}
    else
        table.insert(allConnections[object.id], target)
    end
end
Not sure if we can use table.insert function in our grimrock scripts, but I hope you got the idea of what I am trying to do.

Re: Script Question: Can an object's connections be polled?

Posted: Wed Nov 07, 2012 4:23 pm
by Isaac
3socks wrote:...
That is pretty neat. I can see a use for it in my future projects. 8-)
Thanks