(Runner Tutorial)Spawning more than two types of long and short platforms using the script

Good day Defolders so I’m making an endless runner game with platforms based on the old runner tutorial but I have encountered an issue in the tutorial the game has one type of long platform and one kind of short platform but I created 5 types of short platforms and 5 types of long platforms and I was thinking of a way to make them spawn randomly using the behaviour of the tutorial script I tried creating another local variable to spawn the other ones but it ended up filling the screen with platforms, what changes do I have to make to this script to make that possible again I’m trying to make the game spawn more than two types of platforms but in the way the script does it that it doesn’t fill the screen here is the original script

    	self.gridw = self.gridw + self.speed * dt

    	if self.gridw >= grid then
    		self.gridw = 0

    		-- Maybe spawn a platform at random height
    		if math.random() > 0.2 then
    			local h = platform_heights[math.random(#platform_heights)]
    			local f = "#grassplatform2"
    			if math.random() > 0.5 then
    				f = "#grassplatformlong2"
    			end

    			local p = factory.create(f, vmath.vector3(1600, h, 0), nil, {}, 0.6)
    			msg.post(p, "set_speed", { speed = self.speed })
    		end
    	end
    end

and this is the script of what i tried doing

    -- controller.script
    go.property("speed", 500)

    local grid = 460
    local platform_heights = { 200, 350, 400, 500, 510, 600} -- <1>
    local platforms = "#rockplatform2","#grassplatform2"
    local long_platforms = "#rockplatformlong", "#grassplatformlong2"
    function init(self)
    	msg.post("ground/control#ground", "set_speed", { speed = self.speed })
    	msg.post("Dave#Character", "set_speed", { speed = self.speed })
    	self.gridw = 0
    end
    	
    function update(self, dt) -- <2>
    	self.gridw = self.gridw + self.speed * dt

    	if self.gridw >= grid then
    		self.gridw = 0

    		-- Maybe spawn a platform at random height
    		if math.random() > 0.2 then
    			local h = platform_heights[math.random(#platform_heights)]
    			local f = platforms
    			if math.random() > 0.5 then
    				f = long_platforms
    			end
    local p = factory.create(f, vmath.vector3(1600, h, 0), nil, {}, 0.6)
    msg.post(t, "set_speed", { speed = self.speed })
    		end
    	end
    end

Please help

This is not quite right. If you want a list of strings you need to put them in a Lua table:

local platforms = { "#rockplatform2","#grassplatform2" }
local long_platforms = { "#rockplatformlong", "#grassplatformlong2" }

If you want to pick a random platform from the list you can do like this:

local platform = f[math.random(1, #f)]
local p = factory.create(platform, vmath.vector3(1600, h, 0), nil, {}, 0.6)

Thank you very much it works I tried covering them in curly braces before as a table but I got errors in the console about " url expected but received table" but now every thing works fine and they are behaving like they should but there is a small issue with the collisions if the character lands on either edge of the platforms it messes up the position of the character it either slowly pushes the character backwards even after the player jumps of the platforms and lands on the floor they slowly get pushed off screen or vice versa when landing on the right edge of any platform causes the character to be catapulted faster than it should and he just runs of screen I used a rectangle as the collision shape of my character if that helps

I think you should consider using a sphere instead. It’s not as likely to get stuck.

I’ll try that