Jump to content




I need help with my Program


  • You cannot reply to this topic
4 replies to this topic

#1 M4sh3dP0t4t03

  • Members
  • 255 posts
  • LocationGermany

Posted 14 April 2013 - 10: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()


#2 Imque

  • Members
  • 134 posts

Posted 14 April 2013 - 10: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

#3 Imque

  • Members
  • 134 posts

Posted 14 April 2013 - 10:48 PM

Also:

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


print is case-sensitive like the rest of Lua

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 April 2013 - 10:52 PM

View PostImque, on 14 April 2013 - 10:47 PM, said:

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.

#5 M4sh3dP0t4t03

  • Members
  • 255 posts
  • LocationGermany

Posted 14 April 2013 - 11:03 PM

ok i fixed it now, thanks for your help





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users