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

I need help with my Program

Started by M4sh3dP0t4t03, 14 April 2013 - 09:45 PM
M4sh3dP0t4t03 #1
Posted 14 April 2013 - 11:45 PM
i tried to make a little program to make the redstone gates in my survival world cheaper and smaller but every time I try to tun this i get "bios:337: [string "redgates"]:14: ´=´ expected" here is the code


function ChooseGate(...)
Print("1=NotGate 2=AndGate 3=NandGate 4=OrGate 5=RedClock 6=XorGate 7=XnorGate")
Gate = io.read()
if Gate == 1 then
  NotGate()
elseif Gate == 2 then
  AndGate()
elseif Gate == 3 then
  NandGate()
elseif Gate == 4 then
  Orgate()
elseif Gate == 5 then
  RedClock
elseif Gate == 6 then
  XorGate()
elseif Gate == 7 then
  XnorGate()
end
end
function redclock(...)
Print("RedClock")
Print("Ticks")
clockspeed = io.read()
clockspeedm = tonumber(clockspeed)
clockspeedm = clockspeedm/10
Print("Side")
side = io.read()
while true do
  redstone.setOutput("left", true)
  sleep(clockspeedm/2)
  redstone.setOutput(side, false)
  sleep(clockspeedm/2)
end
end
function AndGate(...)
Print("AndGate")
while true do
  rightredstone = redstone.getInput("right")
  leftredstone = redstone.getInput("left")
  if rightredstone == true and leftredstone == true then
   redstone.setOutput("back", true)
  else
   redstone.setOutput("back", false)
  end
  sleep(0.1)
end
end
function OrGate(...)
Print("OrGate")
while true do
  rightredstone = redstone.getInput("right")
  leftredstone = redstone.getInput("left")
  if rightredstone == true or leftredstone == true then
   redstone.setOutput("back", true)
  else
   redstone.setOutput("back", false)
  end
  sleep(0.1)
end
end
function XorGate(...)
Print("XorGate")
while true do
  rightredstone = redstone.getInput("right")
  leftredstone = redstone.getInput("left")
  if rightredstone == true and leftredstone == false then
   redstone.setOutput("back", true)
  elseif rightredstone == false and leftredstone == true then
   redstone.setOutput("back", true)
  else
   redstone.setOutput("back", false)
  end
  sleep(0.1)
end
end
function NotGate(...)
Print("NotGate")
while true do
  frontredstone = redstone.getInput("front")
  if frontredstone == false then
   redstone.setOutput("back", true)
  else
   redstone.setOutput("back", false)
  end
  sleep(0.1)
end
end
function NandGate(...)
Print("NandGate")
while true do
  rightredstone = redstone.getInput("right")
  leftredstone = redstone.getInput("left")
  if rightredstone == false and leftredstone == false then
   redstone.setOutput("back", true)
  else
   redstone.setOutput("back", false)
  end
  sleep(0.1)
end
end
function XnorGate(...)
Print("XnorGate")
while true do
  rightredstone = redstone.getInput("right")
  leftredstone = redstone.getInput("left")
  if rightredstone == true and leftredstone == true then
   redstone.setOutput("back", true)
  elseif rightredstone == false and leftredstone == false then
   redstone.setOutput("back", true)
  else
   redstone.setOutput("back", false)
  end
  sleep(0.1)
end
end
Print("RedGates 1.0")
ChooseGate()
Imque #2
Posted 14 April 2013 - 11:47 PM
Can I first say your calling a function before it has been loaded:

if true then
  test()
end

function test()
  print("TEST")
end

This would work
Imque #3
Posted 14 April 2013 - 11:48 PM
Also:

Print("RedClock")
Print("Ticks")


print is case-sensitive like the rest of Lua
theoriginalbit #4
Posted 14 April 2013 - 11:52 PM
Can I first say your calling a function before it has been loaded:

if true then
  test()
end

function test()
  print("TEST")
end

This would work
No that will not work…

however this will


function this()
  if true then
	test()
  end
end

function test()
  print("TEST")
end

this()

the reason this is the case is because the functions and variables are loaded top down, but when a statement (i.e. if statement) is encountered that is not in a function it IS evaluated. So in your example the if statement is running before the function is loaded, however in the fix I showed the two functions are loaded and then we attempt to use them, meaning it will work this way…

Now to OP as for the actual problem (except for your order being wrong) is that RedClock is missing the () at the end, so Lua thinks you are trying to assign something to the variable, not call the function.
M4sh3dP0t4t03 #5
Posted 15 April 2013 - 12:03 AM
ok i fixed it now, thanks for your help