Help with js.Variable not being parse as float

Hello, I have this script that is working, except that instead of flat attributes it creates ints.

// Register a new action called "TemplateAction"
let LayerParallaxAction = tiled.registerAction("LayerParallaxAction", function(action) 
{
    let tilemap = tiled.activeAsset;
    
    // Ensure there's a valid tilemap
    if (!tilemap) {
        tiled.alert("No active tilemap found.");
        return;
    }

    let selectedLayers = tilemap.selectedLayers; // Get selected objects
    if (selectedLayers.length === 0) {
        tiled.alert("No objects are selected.");
    } 
    else 
    {
        selectedLayers.forEach(obj => 
        {
            // Create imagePath property if it doesn't exist
            let parallaxFactorX = parseFloat(10.0);
            obj.setProperty("parallaxFactorX", parallaxFactorX); 
            let parallaxFactorY = parseFloat(2.0); 
            obj.setProperty("parallaxFactorY", parallaxFactorY);             
        
        });
    }
});

LayerParallaxAction.text = "add parallax attrs to layer"; // Display name in the menu

tiled.extendMenu("Edit", [
	{ action: "LayerParallaxAction", before: "MapProperties" }
]);

I am not very familiar to js so it’s probably something basic.
Thx

setProperty() creates/changes Custom Properties. If you want to edit the built-in parallax properties, you want to edit obj.parallaxFactor.

If you want to set custom properties but need them to be floats, use setFloatProperty(). This separate method is required because JS doesn’t distinguish between ints and floats with no decimal component, even if you use parseFloat (which is for parsing strings and such).

1 Like

awesome, thanks for the quick response. setFloatProperty() it is.