16 posts
Location
United States, Texas
Posted 01 November 2017 - 12:53 AM
https://pastebin.com/QWDcpwFEI have been trying to impliment a menu selection method into a program with a password lock,
so far I have gotten errors every time I try and press a key when it hits the menu
Line 48 to be exact, I don't know what's happening.
Should be noted running CC 1.41 (MC 1.2.5)
467 posts
Location
Van Diemen's Land
Posted 01 November 2017 - 02:28 AM
I noticed a few things:
1. Your Exit() function is calling on a function called 'c1', however your c1() function is actually with a capital C (C1()), so that'll error out there.
2. Your running the menu inside the password lock, so when you do something with the keyboard (line 81) it goes back to the start of the loop and does it all again. You need to exit out of that loop and start another loop to deal with the arrow keys and enter button. Not too hard. Here's an example of exiting a loop:
while true do
print("Breaking..")
break
end
print("Broke it!")
--# OR the more recommended way
local bRunning = true
while bRunning do
print("Breaking..")
bRunning = false
end
print("Broke it!")
Hope this helps.
477 posts
Location
Germany
Posted 01 November 2017 - 09:31 AM
Another solution would be this:
if input=="Password"then
term.clear()
term.setCursorPos(1,1)
print("-=Welcome Authorized Personnel=-")
term.setCursorPos(1,2)
running = true
while running do
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key,mainMenu)
end
else
And then have Exit() set bRunning to false.
Here is an updated version of your program:
bV3B6XrS
16 posts
Location
United States, Texas
Posted 01 November 2017 - 11:25 PM
Tank you for the replys, I will try them and get back, also with the function for c1 was just when i re-typed it on my pc
16 posts
Location
United States, Texas
Posted 01 November 2017 - 11:41 PM
Davee-ee Jones, Where would I implement that?
467 posts
Location
Van Diemen's Land
Posted 02 November 2017 - 12:32 AM
Davee-ee Jones, Where would I implement that?
I was giving examples of effectively exitting a loop. It looks like (based on your code) that is has already been implemented, though. Good luck! :)/>
16 posts
Location
United States, Texas
Posted 02 November 2017 - 01:59 AM
Another solution would be this:
if input=="Password"then
term.clear()
term.setCursorPos(1,1)
print("-=Welcome Authorized Personnel=-")
term.setCursorPos(1,2)
running = true
while running do
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key,mainMenu)
end
else
And then have Exit() set bRunning to false.
Here is an updated version of your program:
bV3B6XrS
I tried this but it still has the error when it comes to pressing buttons any ideas?
477 posts
Location
Germany
Posted 02 November 2017 - 02:44 PM
Another solution would be this:
if input=="Password"then
term.clear()
term.setCursorPos(1,1)
print("-=Welcome Authorized Personnel=-")
term.setCursorPos(1,2)
running = true
while running do
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key,mainMenu)
end
else
And then have Exit() set bRunning to false.
Here is an updated version of your program:
bV3B6XrS
I tried this but it still has the error when it comes to pressing buttons any ideas?
That's strange it didn't error for me, but I checked in a newer CC Version. Going to check in the specified version when I'm home.
Why are you using an outdated CC/MC Version tho?
16 posts
Location
United States, Texas
Posted 02 November 2017 - 11:53 PM
Another solution would be this:
if input=="Password"then
term.clear()
term.setCursorPos(1,1)
print("-=Welcome Authorized Personnel=-")
term.setCursorPos(1,2)
running = true
while running do
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key,mainMenu)
end
else
And then have Exit() set bRunning to false.
Here is an updated version of your program:
bV3B6XrS
I tried this but it still has the error when it comes to pressing buttons any ideas?
That's strange it didn't error for me, but I checked in a newer CC Version. Going to check in the specified version when I'm home.
Why are you using an outdated CC/MC Version tho?
In an older modpack (Tekkit Classic) I like to go back and play on the version I started with
Edited on 02 November 2017 - 10:53 PM
1023 posts
Posted 03 November 2017 - 05:25 AM
If I am remembering correctly. The version of CC you are using does not have the keys api, so you can not use keys.enter on line 48 (or keys.anything for that matter).
You can either port the keys api to your version (go and grab the api from the current version and just putting it on your computer and calling os.loadAPI on the file), or you can figure out what the key code for enter is.
To figure out what the key code for enter is go to the lua prompt. Type print(textutils.serialize({os.pullEvent("key")})) and then hit the enter key. You should see a serialized table containing the word "key" and the key code the corresponds to the enter key.
477 posts
Location
Germany
Posted 03 November 2017 - 01:39 PM
If I am remembering correctly. The version of CC you are using does not have the keys api, so you can not use keys.enter on line 48 (or keys.anything for that matter).
You can either port the keys api to your version (go and grab the api from the current version and just putting it on your computer and calling os.loadAPI on the file), or you can figure out what the key code for enter is.
To figure out what the key code for enter is go to the lua prompt. Type print(textutils.serialize({os.pullEvent("key")})) and then hit the enter key. You should see a serialized table containing the word "key" and the key code the corresponds to the enter key.
According to the
wiki the keys api has been added in CC 1.4
1023 posts
Posted 03 November 2017 - 08:00 PM
If I am remembering correctly. The version of CC you are using does not have the keys api, so you can not use keys.enter on line 48 (or keys.anything for that matter).
You can either port the keys api to your version (go and grab the api from the current version and just putting it on your computer and calling os.loadAPI on the file), or you can figure out what the key code for enter is.
To figure out what the key code for enter is go to the lua prompt. Type print(textutils.serialize({os.pullEvent("key")})) and then hit the enter key. You should see a serialized table containing the word "key" and the key code the corresponds to the enter key.
According to the
wiki the keys api has been added in CC 1.4
If he is in fact using tekkit classic (as he said in a later reply), then he is using CC version 1.33 (Don't know why they use the older version). In addition the error is attempt to index nil, which means there is a table he is indexing which is nil. The only table he is indexing on line 48 is the keys table.
tekkit classic mods:
https://www.technicpack.net/modpack/tekkit.552560/mods
7083 posts
Location
Tasmania (AU)
Posted 03 November 2017 - 08:34 PM
In which case replacing "keys.enter" with "28" should do the trick,
per the chart here.
16 posts
Location
United States, Texas
Posted 04 November 2017 - 02:20 AM
sweet that worked, thank you all