Code: Select all
characters = {}
characters[1] = {
-- ...
}
characters[2] = {
-- ...
}
-- etc.
Code: Select all
characters = {}
characters[1] = {
-- ...
}
characters[2] = {
-- ...
}
-- etc.
Code: Select all
characters = { player 1
player 2
player 3
player 4}
Code: Select all
player[1] = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 700,
flySpeed = 800,
state = "",
h = 55,
w = 45,
standing = false,
}
player[2] = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 4000,
flySpeed = 8059,
state = "",
h = 55,
w = 45,
standing = false,
}
player[3] = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player[4] = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
Code: Select all
player = player 1
Code: Select all
function love.keypressed(k)
if k == 1 then player = player[1]
elseif k == 2 then player = player[2]
elseif k == 3 then player = player[3]
elseif k == 4 then player = player[4]
end
The key is a string, not a number, and you confuse the player table and the characters table, so I'd do something like:pactace wrote:then have the things that swich them out such as
Code: Select all
function love.keypressed(k)
if characters[tonumber(k)] then
player = characters[tonumber(k)]
end
end
Code: Select all
local function createCharacter( o )
o = o or {}
o.x = o.x or 256
o.y = o.y or 256
o.x_vel = o.x_vel or 0
o.y_vel = o.y_vel or 0
o.jump_vel = o.jump_vel or -4000
o.speed = o.speed or 400
o.flySpeed = o.flySpeed or 859
o.state = o.state or ""
o.h = o.h or 55
o.w = o.h or 45
o.standing = o.standing or false
return o
end
local players = {
createCharacter( { x = 100, y = 200 } ),
createCharacter( { x = 200, y = 210 } ),
createCharacter( { x = 300, y = 220 } ),
createCharacter()
}
local fontHeight
local playerIndex = 1
function love.load()
fontHeight = love.graphics.getFont():getHeight()
end
function love.draw()
local ypos = 5
love.graphics.print( "Current player: " .. playerIndex, 5,ypos )
ypos = ypos + fontHeight
for j,v2 in pairs( players[playerIndex] ) do
love.graphics.print( j .. " = " .. tostring(v2), 10,ypos )
ypos = ypos + fontHeight
end
end
function love.keypressed(key)
if key == " " then
playerIndex = playerIndex + 1
if playerIndex > #players then playerIndex = 1 end
end
end
Code: Select all
if 1 == "1" then
print( "One is one")
else
print( "One isn't one!")
end
Code: Select all
print(false .. " yo")
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 18 guests