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

Get User Input And Check With Variable.

Started by Beatsleigher, 27 July 2013 - 09:23 AM
Beatsleigher #1
Posted 27 July 2013 - 11:23 AM
So I'm creating a custom Minecraft map using CC and a few other mods (Tekkit 3.2.1 - Yes, it's a modpack, but I'm not going over all the different mods) and I'd like the user to input a specific string into a computer, which then outputs a redstone signal, retracting a piston (Redstone inverter).

I've gotten about this far:

shell.run("clear")
print "Please type in the code to open the door to the next room:"
unlockCode = "<Variable content>"
userCode = io.read()
if userCode == unlockCode then
shell.run("redpulse(5)")
else
print "Wrong answer! The program will restart!"
win.Sleep(100)
shell.run("reboot")
end

But something's not right.
For some reason the program exits before the user can even input the string…
Engineer #2
Posted 27 July 2013 - 11:32 AM
Here in CCLua, ComputerCraft Lua, we use a normal read(). without the io :P/>
It should work then if you replace that ( io.read() with read() )


Btw, win.Sleep should be a normal sleep in CCLua.

Spoiler

shell.run("clear")
print "Please type in the code to open the door to the next room:"
unlockCode = "<Variable content>"
userCode = read()
if userCode == unlockCode then
shell.run("redpulse(5)")
else
print "Wrong answer! The program will restart!"
sleep(100)
shell.run("reboot")
end
Beatsleigher #3
Posted 27 July 2013 - 12:00 PM
Here in CCLua, ComputerCraft Lua, we use a normal read(). without the io :P/>
It should work then if you replace that ( io.read() with read() )


Btw, win.Sleep should be a normal sleep in CCLua.

Spoiler

shell.run("clear")
print "Please type in the code to open the door to the next room:"
unlockCode = "<Variable content>"
userCode = read()
if userCode == unlockCode then
shell.run("redpulse(5)")
else
print "Wrong answer! The program will restart!"
sleep(100)
shell.run("reboot")
end

Ah, thanks :)/> I was getting those from the Lua foundation webs…
Thanks for the info :)/>
LBPHacker #4
Posted 27 July 2013 - 12:21 PM
Guys…
shell.run("redpulse(5)")
You sure about that? As far as I know, that should say "No such program". This'll work:
shell.run("redpulse", "5")
Beatsleigher #5
Posted 27 July 2013 - 12:26 PM
Guys…
shell.run("redpulse(5)")
You sure about that? As far as I know, that should say "No such program". This'll work:
shell.run("redpulse", "5")
Yeah. I was just about to edit. Lol.
I found this works:

shell.run("redpulse", "back", "1", "5")
LBPHacker #6
Posted 27 July 2013 - 12:29 PM
Better yet: Replace that part with this:
rs.setOutput("back", true)
sleep(5)
rs.setOutput("back", false)
Self-explaining IMO.