if you want your script to stop and show you the error instead of shutting off setup your cmd file like this
luaplayer test.lua
pause
save it like this and it will pause whenever there is an error :D
that was for savagefreak
Printable View
if you want your script to stop and show you the error instead of shutting off setup your cmd file like this
luaplayer test.lua
pause
save it like this and it will pause whenever there is an error :D
that was for savagefreak
you need to already have directions set, so that at the start it will go these directions. then if you do have that, in your code you need:Zitat:
Zitat von gameo
ect.Code:if direction == "up" then
bally = bally - 2
end
if direction2 == "right" then
ballx = ballx + 2
end
how do i fix an error where it says table index is nil?
Post your script and im sure you'll get alot more response
Yea, We ned to see your sripct, It will make our job more easier:tup:
Zitat:
Zitat von emericaska8r
Would people PLEASE stop repeating things that have already been said?
hay I got two questions
- How do I print a ttf font to screen
I written this code
but all it does is clear the screen.Code:blue = Color.new(0,51,102)
font = Font.load("font.ttf")
while true do
screen:clear()
screen:fontPrint(Font, 0, 0,"ScoreHigh",blue)
screen:waitVblankStart()
screen:flip()
end
- And can someone tell me where i can find a tut on how to assign a table to a image.
Assigning a table to an image? Why not assign an image inside a table, like
table = { img1 = Image.load("img1.png"), img2 = Image.load("img2.png") }
while true do
screen:clear()
screen:blit(0,0,table.img 1)
screen:blit(200,200,table .img3)
screen.waitVblankStart()
screen.flip()
end
lol i'm sorry i wasn't clear i meant like in shines snake game and many other games how they have diff. map pieces in one image
Ah.
screen:blit(x, y, sourceimg, [sourcex, sourcey, width, height])
It's okey Tactical, because i still dont get a f*** damm thing about it.Zitat:
Zitat von -TacticalPaper-
I guess you both explained well, but i just can't figure this (=_=) out!
Oh well, here is how it looks now, and it works without errors:
Zitat:
white = Color.new(255, 255, 255)
screen:print(136, 136, "Loading LUA Pong...", white)
screen.flip()
background = Image.load("Background.pn g")
bat11 = Image.load("Bat1.png")
bat21 = Image.load("Bat2.png")
bat1 = { x = 20, y = 100 }
bat2 = { x = 460, y = 100 }
ball = { x = 240, y = 146 }
ball2 = Image.load("Ball.png")
screen.waitVblankStart(60 )
--assigning this to make the ball move HAHAHAHA that was funny anyways.
ballmoving = nil
while true do
screen:clear()
screen:blit(bat1.x, bat1.y, bat11, true)
screen:blit(bat2.x, bat2.y, bat21, true)
screen:blit(ball.x, ball.y, ball2, true)
pad = Controls.read()
--theres collision for bat1 now for bat 2
if ball.x == bat1.x and ball.y >= bat1.y and ball.x < (16*64) then
ballmoving = "true"
end
--theres paddle 2's collision
if ball.x == bat2.x and ball.y >= bat2.y and ball.x < (16*64) then
ballmoving = "false"
end
if ballmoving == "true" then
ball.x = ball.x + 2
end
if ballmoving == "false" then
ball.x = ball.x - 2
end
if pad:down() then
bat1.y = bat1.y +2
end
if pad:up() then
bat1.y = bat1.y -2
end
if pad:cross() then
bat2.y = bat2.y +2
end
if pad:triangle() then
bat2.y = bat2.y -2
end
if pad:start() then
break
end
screen:print(136, 136, "Welcome to the world of PPP.", white)
screen.waitVblankStart()
screen.flip()
end
Ok well lua player is case sensitive. And you assigned the font to a variable called "font" yet your trying to call it with the word "Font". Im pretty sure they have to be exactly the same so change it toZitat:
Zitat von zmathue
Code:blue = Color.new(0,51,102)
font = Font.load("font.ttf")
while true do
screen:clear()
screen:fontPrint(font, 0, 0,"ScoreHigh",blue)
screen:waitVblankStart()
screen:flip()
end
Code:white = Color.new(255, 255, 255)
screen:print(136, 136, "Loading LUA Pong...", white)
screen.flip()
background = Image.load("Background.png")
bat1 = { x = 20, y = 100, img = Image.load("Bat1.png") }--Put the images in tables
bat2 = { x = 460, y = 100, img = Image.load("Bat2.png") }
ball = { x = 240, y = 146, img = Image.load("Ball.png"), mx = 1, my = 0 }--Put ball's image in it's table
--MX and MY are movemenyx and movementy. Start off mx at 1
screen.waitVblankStart(60)
--Byebyeballmoving
while true do
screen:clear()
pad = Controls.read()
--theres collision for bat1 now for bat 2
if ball.x == bat1.x and ball.y >= bat1.y and ball.x < (16*64) then
ball.mx = -ball.mx
end
--theres paddle 2's collision
if ball.x == bat2.x and ball.y >= bat2.y and ball.x < (16*64) then
ball.mx = -ball.mx --That should make it opposite of ball.mx, making it change directions.
end
--with ballmoving you had the idea but you need more
ball.x = ball.x + ball.mx --This makes the ball move to the right when ball.mx is positive, to the left when its negative.
--Then you can add some stuff dealing with my later. For making it move up//down, do something like
--ball.y = ball.y-ball.my
if pad:down() then
bat1.y = bat1.y +2
end
if pad:up() then
bat1.y = bat1.y -2
end
if pad:cross() then
bat2.y = bat2.y +2
end
if pad:triangle() then
bat2.y = bat2.y -2
end
if pad:start() then
break
end
--blit images at the end, it sometimes can improve efficiency I think
screen:blit(bat1.x, bat1.y, bat11, true)
screen:blit(bat2.x, bat2.y, bat21, true)
screen:blit(ball.x, ball.y, ball2, true)
screen:print(136, 136, "Welcome to the world of PPP.", white)
screen.waitVblankStart()
screen.flip()
end
i had the right case but i changed it when i posted
What does this mean?Code:error: font.lua:5: attempt to index global 'Font' <a nil value>
it means you haven't said what font is before
It means in the file font.lua on line 5 you call the undefined variable "Font"
So, How will i fix it?
Can someone give me a good example of getting the enemy to chase player ?
Theres a good tut over at evilmana.com for it
i followed that one but all i got was <eof> expected near end and got very confused. :(
Well then learn from it and write your own. You arent limited to snippets people hand you.
i'm guessing you probrably just copied and pasted (or typed) the code as it was to your code without making changes to your original and that thats why youre starting to have errors.Zitat:
Zitat von eldiablov
Maybe. but i was going to change it to something more suitable once i got it to work. It's ok now i got it to work. rewriting as we speak. Whats the command for disabling controls ?
You mean for making no buttons do anything?
yeah i want it so when my player meets my enemy that a screen comes up with gameover and credits but i want controls disabled so i that screen will stay there
screen.waitVblankStart(nu mberofsecondsyouwantittos ittheretimes60)
I am trying to make an LUA Side Scroller, and I am having a horrible time thinking of how to make the screen scroll when the character gets close enough. I am doing this tile based, with a text file that creates 2d int arrays for the tile number. How would I be able to scroll the map?
is there a way to get a different texture on each side of the 3d object? Ive been experiementing but cant really find anything to let me do it, I think there is but I cant find anything. If anyone knows please help me.. (by the way, if you do help me please make it relative to the 3d cube that came with luaplayer). :)
i kind of had to scrap my other project because i tried a code scrambling but i forgot to back up my data so i dont know what variables are what... but i guess it would prevent some code theft.
who here knows how to use the analog stick?
That is my script and I get error. Index.lua 50:unexpected symbol near "=".Code:System.usbDiskModeActivate()
blue = Color.new(0,0,255)
green = Color.new(0,255,0)
red = Color.new(255, 0, 0)
player = {x = 1, y = 1, image = Image.createEmpty(32,32)}
enemy = {x = 448, y = 240, image = Image.createEmpty(5,5)}
player.image:clear(blue)
enemyimg = enemy.image:clear(green)
function movement()
if pad:up() then
player.y = player.y - 5
end
if pad:down() then
player.y = player.y + 5
end
if pad:right() then
player.x = player.x + 5
end
if pad:left() then
player.x = player.x - 5
end
end
function AI()
follow = math.random(3)
if follow == 1 then
if player.x > enemy.x then
enemy.x = enemy.x + 10
end
if player.x < enemy.x then
enemy.x = enemy.x - 10
end
if player.y > enemy.y then
enemy.y = enemy.y + 10
end
if player.y < enemy.y then
enemy.y = enemy.y - 10
end
end
end
function collision()
if enemy.y > player.y + player:height() and enemy.y + enemy:height() < player.y and enemy.x < player.x + player:width() and enemy.x + enemy:width() > player.x then
enemy.x = oldenemyx
enemy.y = oldenemyy
player.x = oldplayerx
player.y = oldplayery
player.image:width() = player.image:width() - 1
player.image:height() = player.image:height() - 1
end
end
function endofgame()
if player:width() = 0 and player:height() = 0 then
screen:clear()
screen:print(194, 136, "Game Over", red)
end
end
while true do
oldenemyy = enemy.y
oldenemyx = enemy.x
playery = player.y
playerx = player.x
screen:clear()
pad = Controls.read()
screen:blit(player.x, player.y, player.image)
screen:blit(enemy.x, enemy.y, enemy.image)
movement()
AI()
collision()
endofgame()
screen.flip()
screen.waitVblankStart()
end
Can someone help me I am just trying out to get my AI down and collision and a bunch of stuff working together. I don't even see an error at all.
try changing height and width to number values.Zitat:
Zitat von psp11
No.
if player:width() = 0 and player:height() = 0 then
needs to be
if player:width() == 0 and player:height() == 0 then
Yah, I did screw up there but I still get the same error. I think it is before that.Zitat:
Zitat von -TacticalPaper-
To use the analog stick, refer to the lua snippets thread which tells you how.
I think I know the problem. This is just a guess. The width and height can not be change in my example. I think that they just return numbers and that they can't be changed. I am going to try it out right now.
if you don't look at the snippet, the analog stick's values can be stored into two variables, which show the x and y of the analog stick.Zitat:
Zitat von EminentJonFrost
for example,
dx = pad:analogX()
dy = pad:analogY()
if you move it left, the value of dx will equal -127.
if you move right, the value of dx will equal 128
up, and dy equals -127
down, and dy equals 128
im trying out htis menu style from evilmanaZitat:
Zitat von code
adn i keep getting an error saying
table index is nil
Why not use an easier menu code? If you want, Their is easier ones to learn on evilmana.
Neither currselect or entries have been given a value by this point in the code so what actually happens is:Code:menu[currselect] =1
menu[entries]=table.getn(menu) - 2
Causing the error.Code:menu[nil] =1
menu[nil]=table.getn(menu) - 2