252 posts
Location
The Netherlands
Posted 08 October 2012 - 04:10 PM
Spoiler
Hello,
since I am a noob at lua and I suck at error fixing, I was hoping for someone a bit more experienced to help me with an error I keep getting. I'm trying to make a simple 'shooter'-ish game (like Space Invaders but simpler). So far I've got the key-handling code and the 'ship-drawing code':
local w,h = term.getSize()
local pos = 1
function handleKeys()
local type,key = os.pullEvent()
if key == 203 then
if pos > 2 then
pos = pos-1
end
end
if key == 205 then
if pos < (w-2) then
pos = pos+1
end
end
end
funtion drawShip()
term.setCursorPos((pos,h)
write(" | nooo") -- not 'noooo' but <newline>ooo (it should represent a simple shooter thingy)
end
while true do
term.clear()
handleKeys()
drawShip()
end
Sorry for the potential noobieness, I tried my best :D/>/>
When I try to run this code/program/derp, the console throws the following error:
bios:328: [string "shooter"]:20: '=' expected – (the program's name is 'shooter' by the way)
I can't seem to find the solution to this, so I'm hoping anyone can help me.
Thanks in advance!
~UsernameNevermind, I think I am going to study Lua for the next 10 years so I'll be able to program a decent application or game.
436 posts
Posted 08 October 2012 - 04:22 PM
You've got an extra open parense ( ( ) in there. At term.setCursorPos().
Common bug. I find myself having a similar problem . . . well, a lot of the time.
252 posts
Location
The Netherlands
Posted 08 October 2012 - 04:30 PM
You've got an extra open parense ( ( ) in there. At term.setCursorPos().
Common bug. I find myself having a similar problem . . . well, a lot of the time.
I removed it and it didn't help, it still gave the same error. Thanks anyway :D/>/>
436 posts
Posted 08 October 2012 - 04:39 PM
After reviewing, I come with another possible fix.
This one I don't know to be the case, but I'm pretty sure it is. write needs to be called from its target. ie mon.write(), or in your case term.write(). Probably because of that very difference.
On the other hand, print does not need such a call (because I'm fairly sure it's in the os api).
8543 posts
Posted 08 October 2012 - 07:45 PM
Funtion should be function. Also, if you don't post the exact code with the same number of lines (yours seems to be missing three or so), it's much harder for us to find the error by line number.
252 posts
Location
The Netherlands
Posted 09 October 2012 - 02:51 PM
Thanks for the help. I already warned you for the noobieness and while posting the code it kinda got screwed up -,-
Again, thanks, I'll try it out as soon as I'm home