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

What am I doing wrong? -.-

Started by SporreKing, 24 March 2013 - 07:26 AM
SporreKing #1
Posted 24 March 2013 - 08:26 AM
This is giving me a "quiz2:1: attempt to call nil" error. I'm used to programming outside of minecraft, like java c sharp and javascript. Though i can't see what I'm doing wrong….


question("What year is it?","2012","1564","2013","3")

function question(qu,a1,a2,a3,c)
  term.clear()
  term.setCursorPos(1,1)
  print(qu)
  sleep(2)
  print("1. "+a1)
  sleep(1)
  print("2. "+a2)
  sleep(1)
  print("3. "+a3)
  sleep(1)
  print("Please enter the correct number below:")
  ans = read()
  if ans == c then
	print("CORRECT! Good job!")
	sleep(2)
  else
	print("WRONG! Noob!")
  end
end

Thanks in advance!
MudkipTheEpic #2
Posted 24 March 2013 - 08:27 AM
Move the first line to the bottom. Define functions before calling them.
SuicidalSTDz #3
Posted 24 March 2013 - 08:28 AM
You are calling a function before you define it.

Solution:
Call the function after you define it or define the function before you call it
SporreKing #4
Posted 24 March 2013 - 09:56 AM
Oh…. I see xP Guess I'm too used to Java :P/> Thanks guys!
Engineer #5
Posted 24 March 2013 - 10:25 AM
Nobody notices this?:

print("1.     "+a1)

In LUA we do this by replaceling the + with .. . Like so:

print("1.     " .. a1)

I hope this helped you.