I still get this error - "attempt to index global 'mouse' <a nil value>
Printable View
I still get this error - "attempt to index global 'mouse' <a nil value>
1 moe queston: how would i make collision for a stick figure?? would i have to do it in seperate parts? :confused: thx.
I found a site http://simplythebest.net/sounds/WAV/WAV_sounds.htmlZitat:
Zitat von c5cha7
i have done if for my game. u just cant use the magic wand tool in photohop. it has to be rectangular. the collision still works fine thoZitat:
Zitat von Grimfate126
??? huh? my stik figure has a round head. i want it so that when u shoot a bullet at a certain part, and it HITS the part,(thats where the collisions come in)then, it will do something. so how would u do that for a circle. sry, if i sound confusing. thxZitat:
Zitat von MaSt3r_ShAk3
P.S. to montrob, try this:
Code:background = Image.load("background.png")
mouse1 = Image.load("mouse1.png")
mouse.x = 100
mouse.y = 272
while true do
screen:blit(0, 0, background, false)
screen:blit(mouse.x, mouse.y, mouse1)
pad = Controls.read
if pad:up() then
mouse.y = mouse.y + 1
end
if pad:down() then
mouse.y = mouse.y - 1
end
if pad:left() then
mouse.x = mouse.x - 1
end
if pad:right() then
mouse.x = mouse.x + 1
end
screen.waitVblankStart()
screen:flip()
end
Zitat:
Zitat von Grimfate126
Didn't work.. every time i try to do something i get this error
"attempt to index global 'mouse' <a nil value>"
What does that mean?
Ok umm, i need help making sounds play when i die...i get "attempt to index global 'voice' (a nil value)"Code:ballsound = Sound.load("blip.wav", false)
deathsound = Sound.load("magnum.wav", false)
deathsound = death
ballsound = ball
voice = sound:play()
your sound variable isnt defined. nothing is assigned to it.
Also what are "death" and "ball"?
You already assigned ballsound and deathsound a value, so what are those that you are assigning directly after?
Try something like this...
Code:ballsound = Sound.load("blip.wav", false)
deathsound = Sound.load("magnum.wav", false)
local sound = deathsound
voice = sound:play()
oh, my bad. i figured it out.the correct code:Zitat:
Zitat von montrob
the problems:Code:white = Color.new(255, 255, 255)
background = Image.load("background.png")
mouse = Image.load("mouse1.png")
mousex = 100
mousey = 172
while true do
screen:clear()
pad = Controls.read()
screen:blit(0, 0, background, false)
screen:blit(mousex, mousey, mouse)
if pad:up() then
mousey = mousey - 1
end
if pad:down() then
mousey = mousey + 1
end
if pad:left() then
mousex = mousex - 1
end
if pad:right() then
mousex = mousex + 1
end
screen.waitVblankStart()
screen.flip()
end
1. the variable mouse.x and mouse.y both have periods in them. is LUA, that means that you are assigning those values to an array. EXAMPLE: if i had an array like this:
and then i put mouse.x = 100 and mouse.y= 170 in my code, and started it, the array would now look like this:Code:mouse = {}
BUT, you didnt have an array so it called it a "nil" value, and gave you an error. get what im saying??Code:mouse = { x = 100, y = 170}
2. u had the variables BEFORE the loading. this is'nt so much a problem, but it could interfere with the coding. so ALWYS load everything first, THEN have the variables, THEN your main code.
3. thisis just a tip: evertime you are blitting the same thing to the screen, NEVER put screen:flip() before each time you blit it. this will cause clipping problems. just put
at the VERY END of your code, IN the main loop.Code:screen.waitVblankStart()
screen.flip()
end
thats all i saw! hope u understood ur problems, and good luck with whatever ur doing!!:D:D:D
EDIT: PSPMILLIONAIRE, could u help me with my collisions? read my above posts to see the problem i have. thx!
Grim you will have to use what is called "pixel perfect collision" .
There are solutions for doing this posted all over the internet. Find an example with a simple BASIC language. It will be very much like lua.