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
pactace
Prole
Posts: 38
Joined: Fri Jan 30, 2015 1:25 am

Multiple Charecters

Post by pactace »

I've looked around the forums hoping to find some answer to this question before I asked. I am trying to make a platformer with 4 alternate charecters with different stats such as speed and jump hieght. I need them two cicle at the press of a button do I make each of them a new set of of statistics such as

Code: Select all

player = 	{
				x = 256,
				y = 256,
				x_vel = 0,
				y_vel = 0,
				jump_vel = -700,
				speed = 450,
				flySpeed = 700,
				state = "",
				h = 32,
				w = 32,
				standing = false,
				}
or can I do something less tedious
Very new programmer dont judge
User avatar
zorg
Party member
Posts: 3449
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Multiple Charecters

Post by zorg »

Literally just missed it: viewtopic.php?f=4&t=2490
*unless you were asking about whether you really need to define each character's stats, which in my opinion would be a yes
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
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 »

I cant imagine a different way of having different stats than having different stats, so I guess you'll need different stats :P

You could do this though:

Code: Select all

player = {
  index = 1, -- index of currently selected player
  x = 256, -- shared between chars
  y = 127,
  xvel=0,yvel=0,
  jumpheight = {10, 64, -2, 19},
  vel_multiplier= {1,1,1,4}
}
And then index those values that differ with player.index ofc.

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 »

zorg wrote:Literally just missed it: viewtopic.php?f=4&t=2490
*unless you were asking about whether you really need to define each character's stats, which in my opinion would be a yes
actually I did see that and I tried it in my game it didnt really work
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 »

Sorry wasnt being very specific now that I know that Im going to need to make new stats and such (thank you by the way) How to I make it so when I press a button such as 1 I'll get player 1 and if I press 2 I'll get player two
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 »

Here a hypothisis but maybe this would work

Code: Select all

 characters = {
 player1
 player2
 player3
 player4
  }
           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,
				}
 characters = Player
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
          


thats just my guess
Very new programmer dont judge
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:Here a hypothisis but maybe this would work

Code: Select all

 characters = {
 player1
 player2
 player3
 player4
  }
           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,
				}
 characters = Player
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
          


thats just my guess
That would almost work but doesnt make sense. You reassign The variable player and lose the list of players (that doesnt even work because they arent defined yet anyway)

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 »

Can you improve the code cause I have no Idea what you just said
Very new programmer dont judge
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:Can you improve the code cause I have no Idea what you just said
I could but I won't. If I just give you working code you will never improve and come back with the next question in 5 minutes. You will need to learn and understand on your own, and it seems you have a lot of Lua and programming in general to learn.

I don't know if you have or not, but you should read programming in Lua (again) and then start with something smaller maybe.


And also: why ask "would this work?" You have a computer, go see for yourself.

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 »

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

Who is online

Users browsing this forum: Google [Bot] and 4 guests