Looking for some help

Hello everyone, hope you all had a good New Years and Christmas. Despite the New Years resolutions, my game has decided it’s not going to take part in resolving anything. There’s no error or problem with the game, but I’m working on something that I am to say the least unfamiliar with.

What I am facing is the giving the user the ability to select numerous props that are connected with joints just by selecting one prop. Now that is the easy part which I will most likely finish myself. The harder part is being able to find the joints and list them correctly to be saved to local data and loaded again. You’ve probably guessed that this is giving the user the ability to save full contraptions which is exactly it, I am just about able to figure this out myself.

What I want to know is has anyone tried to achieve something like this before? If so can you share your code? Otherwise is there someone that has ‘specialised’ in this sort of networking entities/joints? Even if you haven’t, if you have a good idea on how this can be completed using a stack function then please share. Thanks!

@luatee hello, happy new year. Cant help you, sorry.
What i would do, i suppose, is create the bodies via a class. Then would create joints via a method of this class, and record in the 2 instance the created link between them. Then it should be fairly easy to browse the linked bodies to find the linked ones?
It would somehow mirror the physical structure of box2D.

@Luatee - if you are adding objects (connected by joints), a table sounds like a good storage system. If the joints are added in strict sequence, then a numbered table works well.

If joints can have multiple objects added, then you will instead need to store a list of objects for each joint (it would be a good idea then to create ID numbers for each item as it is added, to make it easier to reference them).

I have something similar in my 3D model editor, where there is a table of joints that specifies name, position, etc, ie it is a table of tables. Then I have a separate table of bones, each of which connects two joints, that has additional properties. So one table uses the other. When I draw my figure, I loop through the bones, but really, the joints are key, because a bone’s orientation is determined by the position of its end joints. My editor also allows you to rotate joints, which means that all joints connected to that joint have to rotate too. So my editor has to know which joints affect other joints.

If the objects have individual behaviour, you can write classes for them.

In my dungeon, I have a mixture. I use tables to store the dungeon layout, lists of objects (with locations, size etc), and then each interactive object has a class whose code defines its behaviour. So when I walk into a room and my table says it contains a zombie, my zombie class will be used to draw it and move it.

When storing to local data, you obviously need to pack everything into one or more strings, and that requires good organisation. It’s hard to offer advice without knowing more.

As an alternative to storing in local data, you could consider just writing your data out to a code tab, which saves you a lot of trouble. Then Codea can simply read it in next time it runs.

Sorry this is a bit rambling, but it’s difficult to offer help without more details. If anything I’ve described sounds similar to what you are doing, I will be happy to provide more detail.

I have solved this problem and put the code below. Thanks for the advice guys, I’m currently working on saving it all to a text file and changing the id’s in the joints so they match with the new id’s of the box’s and will work correctly. If I run in to any issues I’ll post in detail in this thread.

function Tool:findConnectedProps(prop)
    local bt = {prop}
    local ft = {}
    local ct = self.constraints
    for j,p in pairs(bt) do
        local g = 255/#bt
        p:setColour(j*g,j*g,j*g,255)
        for k,d in pairs(ct) do
            local v = d.j
            if v.bodyA == p.body then
                local nb = v.bodyB
                nb = level:findProp(nb)
                local ad = true
                for i,n in pairs(bt) do
                    if nb.id == n.id then 
                        ad = false
                    end
                end
                if ad then
                    table.insert(bt,nb)
                end
            end
            if v.bodyB == p.body then
                local nb = v.bodyA
                nb = level.ent:findProp(nb)
                local ad = true
                for i,n in pairs(bt) do
                    if nb.id == n.id then 
                        ad = false
                    end
                end
                if ad then
                    table.insert(bt,nb)
                end
            end
        end
    end
    return bt
end

Just put the code there in case anyone else comes across this need like I did.
Edit: Video added to show how it works, mildly interesting!
http://www.youtube.com/watch?v=-Jdhr2qWfMU