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

[LUA][HELP] Can't input

Started by Mackan90096, 20 May 2013 - 04:44 AM
Mackan90096 #1
Posted 20 May 2013 - 06:44 AM
Hi! I'm working on a "shop" thing. (Don't ask why, I'm bored)

But when I try to input a new shop name in the "admin" function with input 1 it wont work, Wont show up. What am I doing wrong? Code:

Edit: I'm also using CC-emu if it's any help

Spoiler


-- Variables --
function name()
local f = fs.open("/shopFiles/settings/name", "r")
shopName = f.readAll()
f.close()
end
w, h = term.getSize()
ownerName = "Admin"
ownerPass = "Admin"
-- Tables --
itemName = { }
itemName[1] = "Item1"
itemName[2] = "Item2"

itemCost = { }
itemCost[1] = 100
itemCost[2] = 100

itemID = { }
itemID[1] = 01
itemID[2] = 02

-- End Tables --
-- End Variables --
function main()
  term.clear()
  term.setBackgroundColor(colors.white)
  term.setTextColor(colors.black)
  term.clear()
  term.setCursorPos(math.floor(w-string.len(shopName))/2,2)
  print(shopName)
  term.setCursorPos(1,3)
  print("ID   Name  Price")
  term.setCursorPos(1,5)
  print(itemID[1].." "..itemName[1].." "..itemCost[1])
  print(itemID[2].." "..itemName[2].." "..itemCost[2])
end

function start()
  name()
  term.clear()
  term.setBackgroundColor(colors.white)
  term.setTextColor(colors.black)
  term.clear()
  term.setCursorPos(math.floor(w-string.len("Login"))/2,2)
  print("Login")
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(math.floor(w-string.len("Username: "))/2,4)
  write("Username: ")
  usrName = read()
  term.setCursorPos(math.floor(w-string.len("Password: "))/2, 6)
  write("Password: ")
  pass = read("*")
  if usrName == ownerName then
	if pass == ownerPass then
	  admin()
	elseif pass == not ownerPass then
	  main()
	end
  else
	main()
  end
end

function admin()
  term.clear()
  term.setBackgroundColor(colors.white)
  term.setTextColor(colors.black)
  term.clear()
  term.setCursorPos(math.floor(w-string.len("Settings"))/2,2)
  print("Settings")
  term.setCursorPos(math.floor(w-string.len("1. Shopname"))/2,4)
  print("1. ShopName")
  term.setCursorPos(math.floor(w-string.len("2. Save and exit"))/2,5)
  print("2. Save and exit")
  term.setCursorPos(math.floor(w-string.len("Setting number: "))/2,7)
  write("Setting number: ")
  input = read()
  if input == 1 then
	local f = fs.open("/shopFiles/settings/name", "w")
	term.setBackgroundColor(colors.white)
	term.setTextColor(colors.black)
	term.clear()
	term.clear()
	term.setCursorPos(1, 1)
	write("Shop Name: ")
	inp = read()
	write(" ")
	f.write(inp)
	f.close()
	admin()
  elseif input == 2 then
	start()
  end
end

function boot()
  local function a()
	sleep(0.2)
  end
  if not term.isColor() then
	print("This requires an advanced computer")
	sleep(1)
	error()
  elseif term.isColor() then
	if fs.exists("/shopFiles/installed") then
	  name()
	  start()
	else
	  term.clear()
	  fs.makeDir("/shopFiles")
	  term.setCursorPos(math.floor(w-string.len("Installing SimpleShop 1.0"))/2,2)
	  print("Installing SimpleShop 1.0")
	  term.setCursorPos(1, 4)
	  print("Created directory /shopFiles")
	  a()
	  fs.makeDir("/shopFiles/users")
	  print("Created directory /shopFiles/users")
	  a()
	  fs.makeDir("/shopFiles/settings")
	  print("Created directory /shopFiles/settings")
	  a()
	  local file = fs.open("/shopFiles/settings/name", "w")
	  file.writeLine("Unnamed Shop")
	  file.close()
	  print("Created file /shopFiles/settings/name")
	  local file = fs.open("/shopFiles/installed", "w")
	  file.write("lol")
	  file.close()
	end
  end
end


boot()
Lyqyd #2
Posted 20 May 2013 - 02:45 PM
Strings aren't numbers. Try comparing the input to "1" instead.
Mackan90096 #3
Posted 21 May 2013 - 04:30 AM
Ah, thanks :)/>

Edit
Using the tostring() function ?
Dlcruz129 #4
Posted 21 May 2013 - 10:13 AM
Use

if input == "1" then
  ...
end