Multiple Charecters

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Multiple Charecters

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
pactace
Prole
Posts: 38
Joined: Fri Jan 30, 2015 1:25 am

Re: Multiple Charecters

Post 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
Very new programmer dont judge
User avatar
pactace
Prole
Posts: 38
Joined: Fri Jan 30, 2015 1:25 am

Re: Multiple Charecters

Post 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
Very new programmer dont judge
User avatar
whitebear
Citizen
Posts: 86
Joined: Sun Mar 15, 2009 1:50 am

Re: Multiple Charecters

Post 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
Last edited by whitebear on Thu Feb 12, 2015 7:08 am, edited 1 time in total.
User avatar
pactace
Prole
Posts: 38
Joined: Fri Jan 30, 2015 1:25 am

Re: Multiple Charecters

Post 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
Very new programmer dont judge
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests