Page 2 of 2

Re: Multiple Charecters

Posted: Tue Feb 10, 2015 11:16 pm
by s-ol
pactace wrote:So something like 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
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
almost. That one "Player" shouldn't be capitalized and the first "end" doesn't make sense and should be removed.

Re: Multiple Charecters

Posted: Wed Feb 11, 2015 12:45 am
by pactace
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

Re: Multiple Charecters

Posted: Wed Feb 11, 2015 3:16 am
by pactace
Hm this code is being weird I have a function

Code: Select all

function player:jump()
		if self.standing then
			self.y_vel = self.jump_vel
			self.standing = false
		end
but when I do my code it says player is a nil value but I cleary just made something that says player1 = player

Re: Multiple Charecters

Posted: Wed Feb 11, 2015 12:45 pm
by whitebear

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
when you call player stats just call player[actP].x, player[actP].speed or what ever
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

but when I do my code it says player is a nil value but I cleary just made something that says player1 = player
you want player to become player1 not the other way around

Re: Multiple Charecters

Posted: Thu Feb 12, 2015 4:00 am
by pactace
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