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

i need some help with my code

Started by Kidgamer100, 02 August 2012 - 12:24 PM
Kidgamer100 #1
Posted 02 August 2012 - 02:24 PM
my code

local input = read("*")
if input == "SteamPower" then
redstone.setOutput("left", true)
sleep(5)
redstone.setOutput("left", false)
if input == "exit" then
sleep(2)
print("shutting down….")
sleep(2)
os.shutdown
end
else
print("wrong password")
end

i put spaces but they didnt show up

when i try to run the program it brings back

bios:206: [string "startup"]:13: '=' exected


Please help.
Cranium #2
Posted 02 August 2012 - 02:44 PM

local input = read("*")
  if input == "SteamPower" then
    redstone.setOutput("left", true)
    sleep(5)
	redstone.setOutput("left", false)
  elseif input == "exit" then --needs to be elseif while creating a menu system like this.
	sleep(2)
    print("shutting down....")
    sleep(2)
    os.shutdown
  else
    print("wrong password")
end

This should work a little better.
Kidgamer100 #3
Posted 02 August 2012 - 03:14 PM

local input = read("*")
  if input == "SteamPower" then
	redstone.setOutput("left", true)
	sleep(5)
	redstone.setOutput("left", false)
  elseif input == "exit" then --needs to be elseif while creating a menu system like this.
	sleep(2)
	print("shutting down....")
	sleep(2)
	os.shutdown
  else
	print("wrong password")
end

This should work a little better.
i get the same bios when i try this
Darky_Alan #4
Posted 02 August 2012 - 03:21 PM
Well.. #1 that's pretty insecure anyone could just hold ctrl + T and terminate your program.
(Meaning they bypass your password COMPLETELY)

#2, I already have a code I wrote for this kind of thing so I guess I can share it, this should work.

Spoiler
function clear()
    term.clear()
    term.setCursorPos(1,1)
end

function door()
    clear()
    local temp = os.pullEvent
    local PASSWORD = "PASSWORD GOES HERE"
    local function dkeys(sawp)
        local disable = {
	    [0] = function() os.pullEvent = temp end,
	    [1] = function() os.pullEvent = os.pullEventRaw end
			  }
	    disable[swap]()
    end
    clear()
    dkeys(1)
    print("Please enter password:")
    write("> ")
    local input = read()
    if input == PASSWORD then
        clear()
        print("Access Granted!")
        textutils.slowPrint("Unlocking...")
        sleep(1)
        clear()
        print("Welcome!")
        redstone.setOutput("left", true)
        sleep(3)
        redstone.setOutput("left", false)
        os.reboot()
    else
        print("Access Denied!")
        sleep(1)
        os.reboot()
    end
end

door()
Kidgamer100 #5
Posted 02 August 2012 - 03:23 PM
Well.. #1 that's pretty insecure anyone could just hold ctrl + T and terminate your program.
(Meaning they bypass your password COMPLETELY)

#2, I already have a code I wrote for this kind of thing so I guess I can share it, this should work.

Spoiler
function clear()
	term.clear()
	term.setCursorPos(1,1)
end

function door()
	clear()
	local temp = os.pullEvent
	local PASSWORD = "PASSWORD GOES HERE"
	local function dkeys(sawp)
		local disable = {
		[0] = function() os.pullEvent = temp end,
		[1] = function() os.pullEvent = os.pullEventRaw end
			  }
		disable[swap]()
	end
	clear()
	dkeys(1)
	print("Please enter password:")
	write("> ")
	local input = read()
	if input == PASSWORD then
		clear()
		print("Access Granted!")
		textutils.slowPrint("Unlocking...")
		sleep(1)
		clear()
		print("Welcome!")
		redstone.setOutput("left", true)
		sleep(3)
		redstone.setOutput("left", false)
		os.reboot()
	else
		print("Access Denied!")
		sleep(1)
		os.reboot()
	end
end

door()
it has a os.pullEvent = os.pullEventRaw at the begaining there more than that thats just the part thats messed up. ill try yours thought
Cranium #6
Posted 02 August 2012 - 03:25 PM

local input = read("*")
  if input == "SteamPower" then
    redstone.setOutput("left", true)
    sleep(5)
    redstone.setOutput("left", false)
  elseif input == "exit" then --needs to be elseif while creating a menu system like this.
    sleep(2)
    print("shutting down....")
    sleep(2)
    os.shutdown() --oops, forgot to add the "()" to the end of this command.
  else
    print("wrong password")
  end
Darky_Alan #7
Posted 02 August 2012 - 03:29 PM
Well.. #1 that's pretty insecure anyone could just hold ctrl + T and terminate your program.
(Meaning they bypass your password COMPLETELY)

#2, I already have a code I wrote for this kind of thing so I guess I can share it, this should work.

Spoiler
function clear()
	term.clear()
	term.setCursorPos(1,1)
end

function door()
	clear()
	local temp = os.pullEvent
	local PASSWORD = "PASSWORD GOES HERE"
	local function dkeys(sawp)
		local disable = {
		[0] = function() os.pullEvent = temp end,
		[1] = function() os.pullEvent = os.pullEventRaw end
			  }
		disable[swap]()
	end
	clear()
	dkeys(1)
	print("Please enter password:")
	write("> ")
	local input = read()
	if input == PASSWORD then
		clear()
		print("Access Granted!")
		textutils.slowPrint("Unlocking...")
		sleep(1)
		clear()
		print("Welcome!")
		redstone.setOutput("left", true)
		sleep(3)
		redstone.setOutput("left", false)
		os.reboot()
	else
		print("Access Denied!")
		sleep(1)
		os.reboot()
	end
end

door()
it has a os.pullEvent = os.pullEventRaw at the begaining there more than that thats just the part thats messed up. ill try yours thought

The way I have mine set up, if you input the correct password you have a 5 second window to terminate, in case you wish to change the password or modify the code.
Kidgamer100 #8
Posted 02 August 2012 - 04:37 PM
Thank you all for your help but i just ended up rewriting it like this

while true do
shell.run("welcome")
os.pullEvent = os.pullEventRaw
term.setCursorPos(31, 8)
local password = read("*")
id password == "password" then
sleep(1)
print("Welcome")
redstone.setOutput("left", true)
sleep(5)
redstone.setOutput("left", true)
elseif password == "edit" then
shell.run("edit", "startup")
end
end