PDA

View Full Version : Help with lua code



crait
August 4th, 2006, 21:47
g'day chaps, and stuff
anyways let me get to it
i need help with lua codes
i put something in that should work, but it wont!
so um, get me on an IM

thecrait (aim)
the_crait (msn)
crait.is (gmail/gtalk)

yaustar
August 4th, 2006, 23:09
Post the code up, you havea better chance of getting it answered. Also stick it in the developers forum.

crait
August 5th, 2006, 02:25
--Kirby's Lua Adventure
--By crait
--Version 0.35
white = Color.new(255,255,255)
green = Color.new(0,255,0)
red = Color.new(255,0,0)
black = Color.new(0,0,0)
healthbar = {}
healthbar.y = 20
Player1 = Image.load("kirby.png")
Player2 = Image.load("kirby2.png")
Playerc = Image.load("crouch.png")
Playerp = Image.load("kirbyp.png")
Player = {}
Player.lives = 4
Player.health = 200
Player.image = Player1
Player.gravity = 200
Player.y = 200
Player.x = 30
Player.jumpspeed = 10
Player.jumpstate = "ground"

background=Image.load("bg.png")
while true do
screen:blit(0,0,background,false)
screen:blit(Player.x,Player.y,Player.image,true)
pad=Controls.read()


if pad:cross() and Player.jumpstate == "ground" and Player.image ~= Playerc then
Player.jumpstate = "jumping"
end


if pad:up()then
Player.image = Player1
end

if pad:down() and Player.jumpstate == "ground" then
Player.image = Playerc
end

if pad:right()then
Player.image = Player1
Player.x=Player.x+4
end

if pad:left()then
Player.image = Player2
Player.x=Player.x-4
end

if pad:r() and Player.health > 0 then
Player.health = Player.health - 20
end

screen:fillRect(0,242,480,30,black)
screen:fillRect(29,259,202,22,white)
screen:fillRect(30,260,200,20,red)
screen:fillRect(30,260,Player.health, healthbar.y, green)
screen:print(30,250, "Health:",green)
screen:print(85, 250,Player.health,green)
screen:print(260,250,"Lives left:",green)
screen:print(260,260,Player.lives,green)
if Player.health <= -1 then
Player.health = Player.health + 1
end
if Player.health <= 0 then
Player.lives = Player.lives - 1
end
if Player.lives <= 0 then
screen:fillRect(100,100,200,50,black)
screen:print(110,110,"Game Over!",red)
screen:print(110,120,"Press (O) to return",red)
screen:print(110,130,"to the Main Menu",red)
if pad:circle() then
dofile("script.lua")
end
if pad:right()then
Player.image = Player1
Player.x=Player.x-4
end
if pad:left()then
Player.image=Player2
Player.x=Player.x+4
end
end
if Player.lives < 0 then
Player.lives = Player.lives + 1
end

if Player.jumpstate == "jumping" then
Player.jumpspeed = Player.jumpspeed - 0.5
Player.gravity = Player.gravity - Player.jumpspeed
end

if Player.gravity < 200 and Player.jumpstate == "falling" then
Player.gravity = Player.gravity + (Player.jumpspeed + 3)
end

if Player.gravity == 200 then
Player.jumpspeed = 10
Player.jumpstate = "ground"
end

if Player.gravity > 200 then Player.gravity = 200
end

Player.y = Player.gravity

screen.flip()
screen.waitVblankStart()
end



ok, thats the code, but for some reason kirby does not change into 'pound mode'

dtothabreezy
August 5th, 2006, 02:58
what part of the code is wrong do u need something like
if jumpstate==jumping and pad:cross then pound

or something else:cool:

crait
August 5th, 2006, 03:02
it loads, just when you press down when your falling, nothing happens

dtothabreezy
August 5th, 2006, 04:11
so u want it to load while your falling

crait
August 5th, 2006, 04:22
no, i want it to load the picture kirbyp if kirby is falling and you press down bottun

dtothabreezy
August 5th, 2006, 05:05
if player.jumpstate=="falling" and pad:down then your image here:D

yaustar
August 5th, 2006, 23:32
Change

if pad:down() and Player.jumpstate == "ground" then
Player.image = Playerc
end
to

if pad:down() then
if Player.jumpstate == "ground" then
Player.image = Playerc
end
if Player.jumpstate == "falling" then
Player.image = Playerp
end
end

crait
August 6th, 2006, 01:26
oh man, thanks yaustar, you are amazing!

crait
August 6th, 2006, 02:00
man... that didnt work either
i tried this

--Kirby's Lua Adventure
--By crait
--Version 0.35
white = Color.new(255,255,255)
green = Color.new(0,255,0)
red = Color.new(255,0,0)
black = Color.new(0,0,0)
healthbar = {}
healthbar.y = 20
Player1 = Image.load("kirby.png")
Player2 = Image.load("kirby2.png")
Playerc = Image.load("crouch.png")
Playerp = Image.load("kirbyp.png")
Player = {}
Player.lives = 4
Player.health = 200
Player.image = Player1
Player.gravity = 200
Player.y = 200
Player.x = 30
Player.jumpspeed = 10
Player.jumpstate = "ground"

background=Image.load("bg.png")
while true do
screen:blit(0,0,background,false)
screen:blit(Player.x,Player.y,Player.image,true)
pad=Controls.read()


if pad:cross() and Player.jumpstate == "ground" and Player.image ~= Playerc then
Player.jumpstate = "jumping"
end


if pad:up()then
Player.image = Player1
end

if pad:down() then
if Player.jumpstate == "ground" then
Player.image = Playerc
end
if Player.jumpstate == "falling" then
Player.image = Playerp
Player.jumpstate = "pound"
end
end

if pad:right() then
Player.image = Player1
Player.x = Player.x+4
end

if pad:left()then
Player.image = Player2
Player.x=Player.x-4
end

if pad:r() and Player.health > 0 then
Player.health = Player.health - 20
end

screen:fillRect(0,242,480,30,black)
screen:fillRect(29,259,202,22,white)
screen:fillRect(30,260,200,20,red)
screen:fillRect(30,260,Player.health, healthbar.y, green)
screen:print(30,250, "Health:",green)
screen:print(85, 250,Player.health,green)
screen:print(260,250,"Lives left:",green)
screen:print(260,260,Player.lives,green)
screen:print(430,252,"V 0.35",white)
screen:print(415,262,"By crait",white)
if Player.health <= -1 then
Player.health = Player.health + 1
end
if Player.health <= 0 then
Player.lives = Player.lives - 1
end
if Player.lives <= 0 then
screen:fillRect(100,100,200,50,black)
screen:print(110,110,"Game Over!",red)
screen:print(110,120,"Press (O) to return",red)
screen:print(110,130,"to the Main Menu",red)
if pad:circle() then
dofile("script.lua")
end
if pad:right()then
Player.image = Player1
Player.x=Player.x-4
end
if pad:left()then
Player.image=Player2
Player.x=Player.x+4
end
end
if Player.lives < 0 then
Player.lives = Player.lives + 1
end

if Player.jumpstate == "jumping" then
Player.jumpspeed = Player.jumpspeed - 0.5
Player.gravity = Player.gravity - Player.jumpspeed
end

if Player.gravity < 200 and Player.jumpstate == "falling" then
Player.gravity = Player.gravity + (Player.jumpspeed + 3)
end
if Player.gravity < 200 and Player.jumpstate == "pound" then
Player.gravity = Player.gravity + (Player.jumpspeed + 4)
end

if Player.gravity == 200 then
Player.jumpspeed = 10
Player.jumpstate = "ground"
end

if Player.gravity > 200 then Player.gravity = 200
end

Player.y = Player.gravity

screen.flip()
screen.waitVblankStart()
end

the game loads fine, its just doesnt want to work

dtothabreezy
August 6th, 2006, 05:16
im absolutley positive that this will work
if pad:down() and player.jumpstate=="jumping"
then your sprite

i tested it my self

yaustar
August 6th, 2006, 05:35
It be nice to say WHAT didn't work in VERY detailed terms.

Edit: Nevermind. The problem is that your Player is NEVER in the falling state.

change

if pad:down() then
if Player.jumpstate == "ground" then
Player.image = Playerc
end
if Player.jumpstate == "falling" then
Player.image = Playerp
Player.jumpstate = "pound"
end
end
to

if pad:down() then
if Player.jumpstate == "ground" then
Player.image = Playerc
end
if Player.jumpstate == "jumping" then
Player.image = Playerp
Player.jumpstate = "pound"
end
end

crait
August 6th, 2006, 06:12
your right
ill try this one yaustar
but make some more mods to itt
man, your really good at this lua thing

crait
August 6th, 2006, 06:55
yep this one worked! thanks everyone!
espescially you Yaustar

acn010
August 6th, 2006, 07:03
im glad it worked