Prevent unavailable color switching crash
This commit is contained in:
parent
e51dc22ca1
commit
b42569eb9c
1 changed files with 11 additions and 11 deletions
22
room.lua
22
room.lua
|
|
@ -341,21 +341,21 @@ function Room:movePlayer(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Room:switchPlayerColor(color)
|
function Room:switchPlayerColor(color)
|
||||||
local canSwitch
|
-- Number keys can request a colour the player has not collected yet. Do
|
||||||
|
-- nothing in that case: there is no corresponding player object to switch
|
||||||
|
-- to (or use as the sound source).
|
||||||
|
local targetPlayer = self.player[color]
|
||||||
|
if not targetPlayer then return false end
|
||||||
|
|
||||||
if self:onlyColorIsActive(color) then
|
local canSwitch = not self:onlyColorIsActive(color)
|
||||||
canSwitch = false
|
if canSwitch then
|
||||||
else
|
for _, c in ipairs(self:getPossibleColors()) do
|
||||||
for _, c in pairs(self:getPossibleColors()) do
|
self:setActiveColor(c, c == color)
|
||||||
if c == color then
|
|
||||||
self:setActiveColor(c, true)
|
|
||||||
else
|
|
||||||
self:setActiveColor(c, false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.player[color]:playSwitchSound(canSwitch)
|
targetPlayer:playSwitchSound(canSwitch)
|
||||||
|
return canSwitch
|
||||||
end
|
end
|
||||||
|
|
||||||
function Room:setActiveColor(color, bool)
|
function Room:setActiveColor(color, bool)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue