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

Attempt to write to global. Fixed(Now unexpected symbol)

Started by Emilgardis, 29 July 2012 - 06:22 PM
Emilgardis #1
Posted 29 July 2012 - 08:22 PM
Apparently I am.
I'm setting up a passcode to my computer for fun.

os.eventPull = os.eventPullRaw
term.clear()
term.setCursorPos(15,9)
x = 3
while x>0 do
write("What is your password? ")
pw = io.read("*")
  if pw == "root" then
print("Welcome back!")
  elseif x == 0 then
os.startTimer(10)
textutils.slowPrint("Shuting down system.\nPlease wait. . .")
os.shutdown()
  else
x = x-1
print("Access denied.\nYou have "..x.." tries left")
  end
break
end
I dont really see the problem.
::EDIT:: I fixed the os.eventPull and os.enventPullRaw to the same but with brackets.
Now I get unexpected symbol.
BigSHinyToys #2
Posted 29 July 2012 - 08:30 PM
some times when messing with os.pullEvent and os.pullEventRaw you can break them, Try rebooting the PC you are using or try restarting minecraft.

[edit] so looking more closly at your code i can see the problem. just give me a min to fix it and post
BigSHinyToys #3
Posted 29 July 2012 - 08:39 PM
Here is code with corrections
Spoiler

os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(15,9)
x = 3
local bRunning = true
while bRunning do
    write("What is your password? ")
    pw = read("*") -- io.read() is diffrent from read()
    if pw == "root" then
	    print("Welcome back!")
	    break
    elseif x == 0 then
	    os.startTimer(10)
	    textutils.slowPrint("Shuting down system.nPlease wait. . .")
	    os.shutdown()
    else
	    x = x-1
	    print("Access denied.nYou have "..x.." tries left")
    end
    if x < 0 then
	    bRunning = false
    end
end
Emilgardis #4
Posted 29 July 2012 - 08:40 PM
Here is code with corrections
Spoiler

os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(15,9)
x = 3
local bRunning = true
while bRunning do
	write("What is your password? ")
	pw = read("*") -- io.read() is diffrent from read()
	if pw == "root" then
		print("Welcome back!")
		break
	elseif x == 0 then
		os.startTimer(10)
		textutils.slowPrint("Shuting down system.nPlease wait. . .")
		os.shutdown()
	else
		x = x-1
		print("Access denied.nYou have "..x.." tries left")
	end
	if x < 0 then
		bRunning = false
	end
end
Explanation please!
BigSHinyToys #5
Posted 29 July 2012 - 08:51 PM
ok

os.eventPull = os.eventPullRaw
This is trying to create a new function in os API you can do that so it thoughts that error
should be

os.pullEvent = os.pullEventRaw


local bRunning = true
in a while true do you cant compare x < 0 because it wants a true or false. so I made this variable to do that and moved the check into an if in the while.



pw = read("*") -- io.read() is diffrent from read()
io read is not the right one here.

and that is all I think just post any other questions
Emilgardis #6
Posted 29 July 2012 - 09:18 PM
ok

os.eventPull = os.eventPullRaw
This is trying to create a new function in os API you can do that so it thoughts that error
should be

os.pullEvent = os.pullEventRaw


local bRunning = true
in a while true do you cant compare x < 0 because it wants a true or false. so I made this variable to do that and moved the check into an if in the while.



pw = read("*") -- io.read() is diffrent from read()
io read is not the right one here.

and that is all I think just post any other questions
what is the differance? And thanks
BigSHinyToys #7
Posted 29 July 2012 - 09:28 PM
honestly I would only be guessing. i don't know the difference other than one works and the other doesn't.
My guess would be that io.read is for input output library (reading out of files) and the other one works with terminal.

Hopefully a real pro will explain it to both of us.
pwajnkaim #8
Posted 14 August 2012 - 02:39 PM
I think the

local bRunning = true

is supposed to have a == if you want it to have a boolean value.
BigSHinyToys #9
Posted 14 August 2012 - 02:52 PM
I think the

local bRunning = true

is supposed to have a == if you want it to have a boolean value.
when comparing varibles in an if we use == when making a varible equal to somthing we use =
example


local a = 1
local b = "hello world"
local c = true
local d = false
local e = nil
if a == 1 then
print("a is onw")
end