252 posts
Posted 02 October 2012 - 01:45 AM
Please help me with the following code if possible:
print("Press [Enter] To Unlock!")
event, key = os.pullEvent("key")
while not key == 13 do -- 13 is the key ENTER
os.sleep(0.1)
until key == 13 then
print("YAY")
end
It gives an error at startup, about a 'too close 'while' at line …' I cut this out of some code so the number would be pointless to give, but if possible please help or correct this code. Thanks.
252 posts
Posted 02 October 2012 - 01:48 AM
Please help me with the following code if possible:
print("Press [Enter] To Unlock!")
event, key = os.pullEvent("key")
while not key == 13 do -- 13 is the key ENTER
os.sleep(0.1)
until key == 13 then
print("YAY")
end
It gives an error at startup, about a 'end expected, (too close 'while' at line #)' I cut this out of some code so the number would be pointless to give, but if possible please help or correct this code. Thanks.
I am using notepad++ and I have closed the function it is in, and that is the only other thing that needs to be closed. I did try closing it but it seems as if "until" closes it as well… If that helps you.
105 posts
Posted 02 October 2012 - 02:06 AM
While and Until are two separate types of loop, and Until .. then is not valid syntax.
print("Press [Enter] To Unlock!")
repeat
event, key = os.pullEvent("key")
os.sleep(0.1)
until key == 13 -- 13 is the key ENTER
print("YAY")
1604 posts
Posted 02 October 2012 - 02:07 AM
You got the while syntax wrong:
while <condition> do
-- code
end
-- or repeat:
repeat
-- code
until <condition>
So your code should be:
function someFunction() -- you said it's on a function
print("Press [Enter] To Unlock!")
repeat
local event, key = os.pullEvent("key")
-- removed the sleep, it's not necesary
until key == 13 then
print("YAY")
end
Edit: ninja'd :)/>/>
252 posts
Posted 02 October 2012 - 02:07 AM
While and Until are two separate types of loop, and Until .. then is not valid syntax.
print("Press [Enter] To Unlock!")
repeat
event, key = os.pullEvent("key")
os.sleep(0.1)
until key == 13 -- 13 is the key ENTER
print("YAY")
Ah, thanks.
1604 posts
Posted 02 October 2012 - 02:09 AM
Oh, a little detail: 13 is not the enter key, it's 28.
252 posts
Posted 02 October 2012 - 02:10 AM
You got the while syntax wrong:
while <condition> do
-- code
end
-- or repeat:
repeat
-- code
until <condition>
So your code should be:
function someFunction() -- you said it's on a function
print("Press [Enter] To Unlock!")
repeat
local event, key = os.pullEvent("key")
-- removed the sleep, it's not necesary
until key == 13 then
print("YAY")
end
Edit: ninja'd :)/>/>
Unexpected symbol on the "Until" line.. I copied what you had said… :3
EDIT: fixed, sorry.
1604 posts
Posted 02 October 2012 - 02:12 AM
Derp, didn't see that you put a then after that. It should be:
function someFunction() -- you said it's on a function
print("Press [Enter] To Unlock!")
repeat
local event, key = os.pullEvent("key")
until key == 28 -- 28 is the enter key
print("YAY")
end
252 posts
Posted 02 October 2012 - 02:13 AM
Oh, a little detail: 13 is not the enter key, it's 28.
Wow, thanks, I was just BARELY experiencing this problem. What had happened is I had found the correct key but got it confused from a thing for adobe keyboard IDs, which I though it was a static id for everything.
1604 posts
Posted 02 October 2012 - 02:15 AM
Oh, a little detail: 13 is not the enter key, it's 28.
Wow, thanks, I was just BARELY experiencing this problem. What had happened is I had found the correct key but got it confused from a thing for adobe keyboard IDs, which I though it was a static id for everything.
Minecraft (and CC) uses
this key codes. In CC 1.4 there's a keys api that makes it easier.