I get this error:
Code:error: index.lua:6: bad argument #1 to `print' (number expected, got nil)
Printable View
I get this error:
Code:error: index.lua:6: bad argument #1 to `print' (number expected, got nil)
slicer4ever
You get the first error because there is one to many ends. You also have an "end" here:
paintballs[i].x = paintballs[i].x + 10 end
For the second error, it means that in one of the variables there is no value (nil), so you have to check at all the places before this one where the defining occurs. There is where your error is. EDIT: I actually think the problem will be gone after you delete the end that I posted in bold.
Gutya, you use two different vars: texty and textY. You see the difference?
texty = 300
screen:print(textX, textY, "Hello World", white)
Well as you can clearly see both the variables have values.
nope the textY one doesn't have a value, because you dont define it.
See for your self. Change the texty in textY.
Argh, the stupidest little mistakes always catch me out! :cry:
Thanks Altair.
np Gutya
Is there any way that i can make a function where when i press X image1.png will change to image2.png for a given amount of time.
Or something similar.
How can i make an image start at one end of the screen then move across?
First one: Yes thats possible. ((almost) anything is)
Make a timer in that function.
Second one:
You blit the image according to x and y coordinates. You can change those and then it moves.
In my code i get this error:
what does it mean?Code:error: index.lua:66: attempt to index global `enemy' (a function value)
i dont know what it exactly means, but i have that all the time. If you post your code, or atleast that line, maybe i can help.
oh, it's okay i had named a function the same as a table in my code. I have another problem if you can help me, can i PM you, i just don't want to show my code to the public yet?
sure i got it and ill take a look
cheers mate.
With this code everything works excpept background is not there.
Code:while true do
screen:blit(0,0,background,false)
character()
enemyset()
screen.waitVblankStart()
screen.flip()
end
Make sure your 2 functions:
character()
enemyset()
don't erase the background
Ahh thanks.
What is wrong here:
Code:if enemy.x > 0 then
enemy.x =+ 10
end
There you go.Code:if enemy.x > 0 then
enemy.x =enemy.x + 10
end
thanks, i have this now, but my enemy wont move.
Code:screen:blit(enemy.x,enemy.y,enemy1)
end
if enemy.x > 0 then
enemy.x = enemy.x + 10
end
screen:blit(enemy.x,enemy.y,enemy1)
screen.flip()
OK, what does your array say?
Code:enemy = {}
enemy.y = 244
enemy.x = 480
Change to:Zitat:
Zitat von Gutya
If you want to add more enemies later then do this:Code:enemy={x=480, y=244}
etc...Code:enemy={}
enemy[1]={x=480, y=244}
enemy[2]={x=460, y=244}
Also, you might want to read PSPillionaire's tutorials, they are really good and they explain all about arrays and anything you need to know about LUA. www.evilmana.com is his website where the tutorials are.
Yes, i know how to do that, and i have read the tutorial, but that doesnt fix my problem at all.
Try that.Code:screen:blit(enemy.x,enemy.y,enemy1)
end
if enemy.x > 0 then
enemy.x = enemy.x - 10
end
screen:blit(enemy.x,enemy.y,enemy1)
screen.flip()
Doesnt work, do you have another soloution? All i want is for enemy1 to move from right to left.
k well i'm back and i seen 1 answer to my question but it didn't help and so you don't have to go all the way back though heres my code to help:
if you look at it it runs fine just when you go though the first 5 then it stops fireing them can someone help me please=-)Code:black=Color.new(0,0,0)
green=Color.new(0,255,0)
bluepaintball=Image.load("C:/Documents and Settings/tim/pspaintball/bluepaintball.png")
oldpad=Controls.read()
currentpaintball=0
ballsxy={}
ballsxy[1]={x=0,y=10}
paintballs={}
for a=1,5 do
paintballs[a]={pic=bluepaintball,firing=false,x=ballsxy[1].x,y=ballsxy[1].y}
end
function paintballsetup()
if currentpaintball < 5 then
currentpaintball = currentpaintball + 1
else
currentpaintball = 1
end
paintballs[currentpaintball].firing=true
end
function paintballfire()
for i=1,5 do
if paintballs[i].firing==true then
paintballs[i].x=paintballs[i].x+10
end
screen:blit(paintballs[i].x, paintballs[i].y, paintballs[i].pic)
if paintballs[i].x>480 then paintballs[i].firing=false
end
end
end
while true do
pad=Controls.read()
screen:clear(black)
if pad:cross() and oldpad:cross() ~=pad:cross() then paintballsetup()
end
paintballfire()
screen:print(10,10,"paintball 1: ".. tostring(paintballs[1].firing),green)
screen:print(10,20,"paintball 2: "..tostring(paintballs[2].firing),green)
screen:print(10,30,"paintball 3: "..tostring(paintballs[3].firing),green)
screen:print(10,40,"paintball 4: "..tostring(paintballs[4].firing),green)
screen:print(10,50,"paintball 5: "..tostring(paintballs[5].firing),green)
screen:print(10,110,currentpaintball,green)
screen.waitVblankStart()
screen.flip()
oldpad=pad
end
ok ive got my randomization problem down to the part theres an error at
the blue part is where the error is at. when i get rid of the if statment and just leaveCode:math.randomseed(os.time() )
background = Image.load("background.PNG")
player = Image.load("ball.PNG")
block = Image.load("block.PNG")
space = Image.load("white.PNG")
--Variables
XAxis=100
YAxis=100
L1=0
System.usbDiskModeActivate()
while true do
screen:clear()
screen:blit(0, 0, background, false)
screen:blit(XAxis, YAxis, player)
pad = Controls.read()
if pad:start() then
break
end
if pad:right() then
if XAxis<448 then
XAxis=XAxis+6
else
XAxis=448
end
end
if pad:left() then
if XAxis>0 then
XAxis=XAxis-6
else
XAxis=0
end
end
--First Line
Line1 = {0,0,0,0,0,0,0,0}
if L1==0 then
Line1[1]=math.random(0,1)
Line1[2]=math.random(0,1)
Line1[3]=math.random(0,1)
Line1[4]=math.random(0,1)
Line1[5]=math.random(0,1)
Line1[6]=math.random(0,1)
Line1[7]=math.random(0,1)
Line1[8]=math.random(0,1)
YVars1=272
L1=1
end
if L1==1 then
YVars1=YVars1-2
if Line1[1]==0 then
screen:blit(0, YVars1, block)
end
if Line1[1]==1 then
screen:blit(0, YVars1, space)
end
if Line1[2]==0 then
screen:blit(60, YVars1, block)
end
if Line1[2]==1 then
screen:blit(60, YVars1, space)
end
if Line1[3]==0 then
screen:blit(120, YVars1, block)
end
if Line1[3]==1 then
screen:blit(120, YVars1, space)
end
if Line1[4]==0 then
screen:blit(180, YVars1, block)
end
if Line1[4]==1 then
screen:blit(180, YVars1, space)
end
if Line1[5]==0 then
screen:blit(240, YVars1, block)
end
if Line1[6]==1 then
screen:blit(300, YVars1, space)
end
if Line1[6]==0 then
screen:blit(300, YVars1, block)
end
if Line1[7]==1 then
screen:blit(360, YVars1, space)
end
if Line1[7]==0 then
screen:blit(360, YVars1, block)
end
if Line1[8]==1 then
screen:blit(420, YVars1, space)
end
if Line1[8]==0 then
screen:blit(420, YVars1, block)
end
screen.flip()
end
if YVars1==0 then
YVars1=272
L1=0
end
end
it does the randomization fine. but when i add it back in it never assigns them the new number.Code:Line1[1]=math.random(0,1)
Line1[2]=math.random(0,1)
Line1[3]=math.random(0,1)
Line1[4]=math.random(0,1)
Line1[5]=math.random(0,1)
Line1[6]=math.random(0,1)
Line1[7]=math.random(0,1)
Line1[8]=math.random(0,1)
YVars1=272
L1=1
in thery this should write "hello" to the screen right?
if menustatus == 0 then
screen:print(10, 10, "hello", green)
screen:blit(0,0,bg1)
screen.flip()
end
its part of a menu, im wondering why doesnt the text show
edit nevermind, all i had to do was flip the text and pic around
maybe because L1 is never 0 :P ?
I do call it in beggin9ng though. plus when it reaches the top of the screen it sets L1 to L1=0
help! when I try to exit my code, this happens. It returns to the last thing. example menu. Because this is a new file it does that but how can I stop it from that? here it is:
I realize "break" brings it back to the menu but how can i prevent that?Code:while true do
screen:clear()
screen:print(165,130,"Thanks for playing!",green)
screen.flip()
screen.waitVblankStart(120)
break
end
Just add a var, say "exit", and if that var is, lets say 1, then just do another break:
Then put this in your menu:Code:while true do
screen:clear()
screen:print(165,130,"Thanks for playing!",green)
screen.flip()
screen.waitVblankStart(12 0)
exit=1
break
end
Code:if exit == 1 then
break
end
arg i cant remeber the line of code it was sometin like os seed, to make it randomize something everytime
thanks
o and i got it to work=-)
thanks man. I owe you one :icon_winkZitat:
Zitat von Altair
no prob!
is there any wildcards for lua? i noticed plain * wont work
and is there something that will write all button input into a text file,
Ok i found the problem. Since I was creating the table in the while loop it kept assigning it that values.
last problem of the day,, with my guitar program, if you keep hitting the notes over and over again, the sounds get louder and louder and start to hiss.
its very noticible, and thats whats keeping me for releasing v0.2,,
so i want to know how to fix it, ive tryed oldpad but you need to press the button the exact same time for it to make a sound,,
what else can i do to stop that