Ohh... i understand... theres multiple ways...
Printable View
Ohh... i understand... theres multiple ways...
I'm just making a for-fun script that has a visual effect, well, what I'm trying to achieve is a visual effect.
an error that keeps popping up: lua: 36 : argument was incorrect
heres my short script:
whats wrong? :confused:Code:black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
width = 480
height = 272
while true do
pad = Controls.read()
if pad:cross() then
break
end
screen:clear(black)
h = math.random(1, 100)
x = width/h
y = height/h
z = math.random(1, 4)
if z == 1 then
screen:pixel(x, y, white)
end
if z == 2 then
screen:pixel(x, y, red)
end
if z == 3 then
screen:pixel(x, y, green) -- this is line 36
end
if z == 4 then
screen:pixel(x, y, blue)
end
screen.flip()
screen.waitVblankStart()
end
try this:Zitat:
Zitat von EminentJonFrost
you should use elseif statemnts, they lower the chance of an error bigtime.Code:math.randomseed(os.time())
black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
width = 480
height = 272
h = math.random(1, 100)
z = math.random(1, 4)
x = width/h
y = height/h
while true do
pad = Controls.read()
if pad:cross() then
break
end
screen:clear()
if z == 1 then
screen:pixel(x, y, white)
elseif z == 2 then
screen:pixel(x, y, red)
elseif z == 3 then
screen:pixel(x, y, green)
elseif z == 4 then
screen:pixel(x, y, blue)
end
screen.flip()
screen.waitVblankStart()
end
how can i do
if player.y == 138(pixel on my screen) then gravity = 138 so tha when i jump i don't past trugh the floor. cause the floor im jumping on is higher
you need to post a little more coding up.Zitat:
Zitat von ZereoX
Here is the part of my code
i want to do when the legs of the player that mean the player.y touches the floor where its higher then the normal floor the gravity changes so that he stay on and not pass true it up to the same high as the prvious floor.Code:player = {}
player.gravity = 160
player.y = 230
player.x = 50
player.jumpspeed = 10
player.jumpstate = "ground"
while true do
pad = Controls.read()
screen:clear()
screen:blit(0,0,Background1)
if pad:r() and oldpad:r() ~= pad:r() then
bulletSetup()
end
if pad:left() then
player.x = player.x - 2
end
if pad:right() then
player.x = player.x + 2
end
if pad:cross() and player.jumpstate == "ground" then player.jumpstate = "jumping" end
if player.jumpstate == "jumping" then
player.jumpspeed = player.jumpspeed - 0.5
player.gravity = player.gravity - player.jumpspeed
end
if player.gravity < 0 then
player.jumpstate = "falling"
end
if player.gravity < 160 and player.jumpstate == "falling" then
player.gravity = player.gravity + (player.jumpspeed + 3)
end
if player.gravity == 160 then
player.jumpspeed = 10
player.jumpstate = "ground"
end
if player.gravity > 160 then player.gravity = 160 end
player.y = player.gravity
screen:blit(player.x,player.y,player1)
screen:blit(0,0,ground)
try it now.Code:player = {}
player.gravity = 160
player.y = 230
player.x = 50
player.jumpspeed = 10
player.jumpstate = "ground"
while true do
pad = Controls.read()
screen:clear()
screen:blit(0,0,Background1)
if pad:r() and oldpad:r() ~= pad:r() then
bulletSetup()
end
if pad:left() then
player.x = player.x - 2
end
if pad:right() then
player.x = player.x + 2
end
if pad:cross() and player.jumpstate == "ground" then player.jumpstate = "jumping" end
if player.jumpstate == "jumping" then
player.jumpspeed = player.jumpspeed - 0.5
player.gravity = player.gravity - player.jumpspeed
end
if player.gravity < 0 then
player.jumpstate = "falling"
end
if player.gravity < 160 and player.jumpstate == "falling" then
player.gravity = player.gravity + (player.jumpspeed + 3)
end
if player.gravity == 160 then
player.jumpspeed = 10
player.jumpstate = "ground"
end
if player.gravity > 160 then player.gravity = 160 end
player.y = player.gravity
screen:blit(player.x,player.y,player1)
screen:blit(0,0,ground)
second_floor = {}
second_floor.y = 220 -- made it lower, just in case the player cant reach.
second_floor.x1 = 100
second_floor.x2 = 200
if player.y <= second_floor.y and player.x >= second_floor.x1 and player.x <= second_floor.x2 then
player.y = second_floor.y -- I forgot the ".y" last time.
end
i made two changes from the last time, one correcting a stupid mistake on my part.
does't work it don't even change somthing.
Want me to send everything or you still have.
Well instead of changing player.gravity you could sayZitat:
Zitat von ZereoX
Code:if player.y >= 138 then
player.y = 138
noone yet helped me yet, (i think noone knows how to fix it).Code:if true then
screen:blit(x1, y1, player2)
x1 = x1 + 2
end
if true and pause == true then
screen:blit(x0, y0, up2)
screen.flip()
screen.waitVblankStart(10 )
screen:blit(x0, y0, up1)
screen.flip()
screen.waitVblankStart(10 )
y0 = y0 - 2
end
if pad:up() then
pause = true
end
anyways, is there a way to make the up1 and up2 change after each move?