This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Escius's profile picture

Noob Question

Started by Escius, 12 July 2012 - 11:16 PM
Escius #1
Posted 13 July 2012 - 01:16 AM
Excuse me if the answer to my problem is extremely obvious. I just started Lua today, so I'm sure it is.

I'm trying to make a sort-of selector using the arrow keys. It's used to cycle through a list of options.

Here's a small snippet of the code I'm using:

while true do
event, param1 = os.pullEvent()
if event == "key" and param1 == "208" then break
end
end

The problem is, I can't get any keys to register. I believe 208 is the down arrow key. I've tried multiple IDs for keys, including the other arrow keys, and even some characters.

If I use
if event == "char" and param1 == "g" etc,
then it works just fine. Something about using "key" instead of "char" just won't work for me.
The only problem with using "char", is that I'm unable to use the arrow keys.

Please help!
MysticT #2
Posted 13 July 2012 - 01:18 AM
The argument for the "key" event is a number, not a string. Remove the quotes from the key code and it should work.
Escius #3
Posted 13 July 2012 - 01:21 AM
That worked! Thank you.