Looking for a way to choose one of two values for my enemy to spawn from.

Hi, I know there is probably a real simple way to do this but i’ve been scratching my brain for ages trying to work it out.

I want my spawned enemy to pick one of two numbers to spawn from either 0 or 1200 so it comes from either the left or right of the screen.

Please someone help me out!

Thanks,

Finn M.

Because not all devices have the same resolution, you would be better served using a left/right boolean variable, and based on that use 0 and the display.contentWidth value to determine where to place the monster.

Here’s some pseudo code.

local spawnLeft = (math.random(100) \<= 50) -- This will be a true or false value, with an equal chance of either one being the case. if(spawnLeft) then -- Spawn the monster at 0 else -- Spawn the monster at display.contentWidth end

Thanks for the help sheppe that did the trick!

Because not all devices have the same resolution, you would be better served using a left/right boolean variable, and based on that use 0 and the display.contentWidth value to determine where to place the monster.

Here’s some pseudo code.

local spawnLeft = (math.random(100) \<= 50) -- This will be a true or false value, with an equal chance of either one being the case. if(spawnLeft) then -- Spawn the monster at 0 else -- Spawn the monster at display.contentWidth end

Thanks for the help sheppe that did the trick!