Page 1 of 1

How to access custom properties from Tiled

Posted: Sun Oct 16, 2022 3:40 pm
by ELT7902
Hi everyone, I am new to the forums, and this is my first post.

So I'm using Bump and STI for this project. I have an object layer in Tiled named "One Way", that will represent jump-through platforms. It has the custom property "collidable", which allows the layer to be considered solid. What I'm trying to figure out is, how to access that property from my code, and change it to false. The idea is, I want to disable the collision as long as the player is below the platform, and have it be true when I'm above. The code below that I tried doesn't seem to disable the collision, and it still treats the platform as a full on solid that the player can't jump through:

Code: Select all

for i, v in ipairs(gameMap.layers["OneWay"].objects) do
    if Player.y > v.y then
	v.properties.collidable = false -- Trying to access the collidable property from tiled
    else
    	v.properties.collidable = true -- Trying to access the collidable property from tiled
    end
end

If any more code is needed, or if there's anything I should specify, let me know. Thanks in advance!

Re: How to access custom properties from Tiled

Posted: Mon Oct 17, 2022 12:36 am
by SelfDotX
Never used Tiled before, but took a quick look at the API and this stood out
Modifications to the properties will not affect the original object.
Which led me to here
Replaces all currently set custom properties with a new set of properties.
Hope that helps!

Re: How to access custom properties from Tiled

Posted: Mon Oct 17, 2022 6:46 pm
by ELT7902
I ended up finding a better way to do it. Here is the new working code:

Code: Select all

function Player:filter(other)
    if other.type == "OneWay" then
        if self.y + self.height <= other.y then
            return "slide"
        end
    else
        return "slide"
    end
end
For anyone who stumbles upon this, I just gave the player a filter function that does the one way checking. I then gave my platform object a variable called 'type', which is a string representing whatever name you want for your object. You would then pass the filter function as an argument into the player's world:move(). Understanding filters is very useful when it comes to utilizing bump effectively. Here is a link to the documentation, which of course, helps tremendously! https://github.com/kikito/bump.lua. Thanks anyway!