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

startup problemo

Started by SGunner2014, 01 September 2014 - 01:48 PM
SGunner2014 #1
Posted 01 September 2014 - 03:48 PM
Hi,

I'm relatively new to computercraft and I couldn't work out how to get my startup program to run another program if it already hasn't been run.

Here's my startup:


--[CLIENT]--
term.clear()
term.setCursorPos(1,1)
rednet.open("right")
print("Login ID required.")
local user = read()
rednet.send(0, user..".1")
start = 1
while start == 1 do
event, id, text = os.pullEvent()
if event == "rednet_message" then
  if text == "succ01.2" then
	print("Passcode required.")
	pass = read("*")
	rednet.send(0, pass..".3")
	while true do
	local event, id, text = os.pullEvent()
	  if event == "rednet_message" then
		if text == "succ01.4" then
		  print("Logged in successfully!")
		  start = 2
		  shell.run("firsttime")
		  break
		elseif text == "fail01.4" then
		  print("Incorrect password.")
		  sleep(2)
		  os.reboot()
		end
	  end
	end
  end
end
end
And here's the "firsttime" program it runs:



local Table = {complete = "firsttimedone"}
if complete == true then
  term.clear()
  print("Logged in successfully.")
else
  print("First time setup running.")
  print("Please enter a username to use with services.")
  local userservices = read()
  print("Your username has been set to "..userservices)
  print("First time setup complete.")
  shell.run("firsttimecomplete")
end

And here's the "firsttimecomplete" program it runs:

local firsttimecomplete = true

Can you spot any errors or possibly help me to finish this?

Thanks,
- Sam
Zudo #2
Posted 01 September 2014 - 04:21 PM
What errors are you experiencing? I can't see anything wrong, but I don't understand your problem entirely.
Edited on 01 September 2014 - 02:22 PM
SGunner2014 #3
Posted 01 September 2014 - 04:25 PM
Well, when the "firsttime" program runs, it doesn't detect that "firsttimecomplete" in the program "firsttimecomplete" is equal to true, and therefore just runs the "firsttime" program with the else bit. I have already run the program "firsttimecomplete" and the variable within should be equal to true and therefore should be picked up by the "firsttime" program and then it should run the first if bit instead of the else bit.

Thanks,
- Sam
KingofGamesYami #4
Posted 01 September 2014 - 04:49 PM
local variables are confined to the script that creates them. Rather than shell.run( "firsttimecomplete" ), do something like:

  print("First time setup complete.")
  firstTimeComplete = true --#a global declaration is accessible to all programs (until you restart the computer)
end
SGunner2014 #5
Posted 01 September 2014 - 05:04 PM
Okay, thanks.

What I will do is have another computer running constantly which checks for messages coming in with a specific protocol and if the protocol is correct, it will replace the firsttimesetup with true on the server.

I will also edit the "firsttime" program to query a global table and see if the first time setup has been run.

Yay, servers!

Thanks,
- Sam