Spawn 1 of each value only randomly

Hey dip,

yeah, I forgot incorporating your already existing spawn mechanics.

I implemented them below and added some comments for better understanding.

local enemyList = {"blue", "red", "green"} --this is the list of enemy names local enemyColors = {} --this is the copy of the enemy list that is used for shuffling local enemyGraphics = {} --this table holds the enemy graphics for positioning them later for i=1, #enemyList do local color = enemyList[i] enemyColors[i] = color --copy enemy name into the enemyClors table local enemy if enemyName == "blue" then --create blue enemy enemy = display.newSprite(imageSheetRectangle, sequenceDataRectangle) enemy.name = "Blue" physics.addBody(enemy, { isSensor = true }) enemy:setSequence("blueRect") enemy:setFrame(3) elseif enemyName == "red" then --create red enemy enemy = display.newSprite(imageSheetCross, sequenceDataCross) enemy.name = "Red" physics.addBody(enemy, {isSensor = true }) enemy:setSequence("blueCross") enemy:setFrame(1) else --create green enemy enemy = display.newSprite(imageSheetCircle, sequenceDataCircle ) enemy.name = "Green" physics.addBody(enemy, { isSensor = true }) enemy:setSequence("blueCirc") enemy:setFrame(2) end   enemyGroup:insert(enemy) enemy.isVisible = false --hide graphic initially enemyGraphics[color] = enemy --add graphic to the enemyGraphics table for later use end local function table\_shuffle(t) --local table shuffling funtion assert(t, "table.shuffle() expected a table, got nil") for i = #t, 2, -1 do local j = math.random(1, i) t[i], t[j] = t[j], t[i] end print("Shuffling Done") end table.shuffle = table\_shuffle function shuffleColors() --call this function whenever you want to position or reposition the enemys table\_shuffle(enemyColors) --colors are shuffled for i=1, #enemyColors do local enemy = enemyGraphics[enemyColors[i]] --the previously created graphic is picked local posX = (i-1)\*120 + 40 --x position is estimated enemy.x = posX enemy.y = display.contentHeight - 550 enemy.isVisible = true --show the graphic if enemy.movement then transition.cancel(enemy.movement); enemy.movement = nil end --if the graphic moved before, we want to cancel that movement enemy.movement = transition.to(blue, { time=moveRate, y=600}) --store transition so it can be cancelled later end end

Hope it’s clearer now :slight_smile:

Aha I see now. Yeah that’s perfect, thanks for the help torbenratzlaff, and also for the great explanations.

You’re welcome :slight_smile: