almost. That one "Player" shouldn't be capitalized and the first "end" doesn't make sense and should be removed.pactace wrote:So something like thisCode: Select all
player1 = { x = 256, y = 256, x_vel = 0, y_vel = 0, jump_vel = -4000, speed = 400, flySpeed = 859, state = "", h = 55, w = 45, standing = false, } player2 = { x = 256, y = 256, x_vel = 0, y_vel = 0, jump_vel = -4000, speed = 400, flySpeed = 859, state = "", h = 55, w = 45, standing = false, } player3 = { x = 256, y = 256, x_vel = 0, y_vel = 0, jump_vel = -4000, speed = 400, flySpeed = 859, state = "", h = 55, w = 45, standing = false, } player4 = { 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 = player1 end function love.keypressed(k) if k == 1 then player = player1 elseif k == 2 then player = player2 elseif k == 3 then player = player3 elseif k == 4 then player = player4 end end
Multiple Charecters
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Multiple Charecters
Re: Multiple Charecters
thanks man so this?
Code: Select all
player1 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player2 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player3 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player4 = {
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 = player1
function love.keypressed(k)
if k == 1 then player = player1
elseif k == 2 then player = player2
elseif k == 3 then player = player3
elseif k == 4 then player = player4
end
end
Very new programmer dont judge
Re: Multiple Charecters
Hm this code is being weird I have a function but when I do my code it says player is a nil value but I cleary just made something that says player1 = player
Code: Select all
function player:jump()
if self.standing then
self.y_vel = self.jump_vel
self.standing = false
end
Very new programmer dont judge
Re: Multiple Charecters
Code: Select all
actP= 1
player = {}
player[1] = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -700,
speed = 450,
flySpeed = 700,
state = "",
h = 32,
w = 32,
standing = false
}
player[2] = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -700,
speed = 450,
flySpeed = 700,
state = "",
h = 32,
w = 32,
standing = false
}
player[3] = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -700,
speed = 450,
flySpeed = 700,
state = "",
h = 32,
w = 32,
standing = false
}
player[4] = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -700,
speed = 450,
flySpeed = 700,
state = "",
h = 32,
w = 32,
standing = false
}
function love.keypressed(k)
if k == 1 or k == 2 or k == 3 or k = 4 then
actP = tonumber(k)
end
end
also using non strings are marginally faster for "states". I personally prefere somewhere intorduce globals. example:
Code: Select all
PLAYER_STATES_IDLE = 0
PLAYER_STATES_WALK = 1
PLAYER_STATES_JUMP = 2
PLAYER_STATES_STUN = 3
PLAYER_STATES_DEAD = 4
PLAYER_STATES_DANCE = 5
if player[actp].state == PLAYER_STATES_JUMP then
--draw my jumping sprite
end
you want player to become player1 not the other way aroundbut when I do my code it says player is a nil value but I cleary just made something that says player1 = player
Last edited by whitebear on Thu Feb 12, 2015 7:08 am, edited 1 time in total.
Re: Multiple Charecters
ok I get everything you just said besides the .acts and
Code: Select all
function love.keypressed(k)
if k == 1 or k == 2 or k == 3 or k = 4 then
actP = tonumber(k)
end
Very new programmer dont judge
Who is online
Users browsing this forum: No registered users and 6 guests