Jump to content




[Error] attempt to get length of nil


  • You cannot reply to this topic
1 reply to this topic

#1 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 08 August 2012 - 12:56 AM

I was following some directions from Here, and I received an error.
I just tried to use the code for the multiple options, and got an error: test:3: attempt to get length of nil.
Here's how I used it:
function opt(m) --renamed just for sake of ease on my part.
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
I also used the table like this:
local options={
"Redstone/Red alloy wire",
"White",
"Orange",
"Magenta",
"Light Blue",
"Yellow",
"Lime",
"Pink",
"Gray",
"Light Gray",
"Cyan",
"Purple",
"Blue",
"Brown",
"Green",
"Red",
"Black"
}
Is there supposed to be something that goes in the () when calling it?

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 08 August 2012 - 01:17 AM

I just figured it out on my own... I was supposed to call it as opt(options)
The "m" stood for the table that you are creating for that specific option menu.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users