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

Changing Variables Through If Then Statements

Started by Mango845, 23 July 2013 - 12:42 PM
Mango845 #1
Posted 23 July 2013 - 02:42 PM
I am very new to computercraft. I am trying to change a variable through an if then statement. Here is my code

local mtime
local mside
print("Should I make blocks(b ) or ingots(i)?")
local ch = tostring( read() )
if ch == b then
mtime = 14
mside = left
end
if ch == i then
mtime = 3
mside = right
end
print(mtime)

this is the part where im renaming the variables, there is more to the program but the rest is not important
the problem is that the variable dont seem to be changing. I set it to print, but nothing shows up when it prints, as if the variable hasnt been assigned.

Please help
Lyqyd #2
Posted 23 July 2013 - 08:50 PM
Split into new topic.


if ch == "b" then
  -- change stuff
elseif ch == "i" then
  -- change other stuff
end
Zudo #3
Posted 24 July 2013 - 01:36 AM
Split into new topic.


if ch == "b" then
  -- change stuff
elseif ch == "i" then
  -- change other stuff
end

Yes, your if statement is trying to compare an input ("b" or "i") to a nonexistent variable(b or i)