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

[Error] attempt to index ? Table Selection problem

Started by Fiery Arcanine, 11 November 2012 - 11:07 PM
Fiery Arcanine #1
Posted 12 November 2012 - 12:07 AM
I'm trying to make some kind of Pokemon Battle Simulator.
Now I'm making the move selection table but I get this error:
pbsselect:30: attempt to index ? (a nil value)

Now I tried to look it up, but I cant find any error's.

here is the code:

Spoiler


function yN()
  selection=1
	while true do
	  term.clear()
	  term.setCursorPos(1,1)
	  local x, y=term.getCursorPos()
	  term.clearLine()
	  if selection==1
		then write(">Attack< Exit ")
		else write (" Attack >Exit<") end
	  term.setCursorPos(x, y)
	  a, b=os.pullEvent()
	  while a~="key"
	  do a, b=os.pullEvent() end
	if b==203 and selection==2 then selection=1 end
	if b==205 and selection==1 then selection=2 end
	if b==28 then print ("") break end
	end
  if selection==1 then return true end
  if selection==2 then return false end
  return false
end

function atk()
  attack=1
  while true do
	term.clear()
	term.setCursorPos(1,2)
	for i=1, 5, 1 do
	  if i==attack then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
	  end
	print("Select your move:")
	a, b= os.pullEventRaw()
	if a == "key" then
	if b==200 and attack>1 then attack=attack-1 end
	if b==208 and attack<=1 then attack=attack+1 end
	if b==28 then break end
	end
  end
  term.clear()
  term.setCursorPos(1,1)
  return attack
end


while yN() == true do
  if selection == 1 then
	local moves={
	"Tackle",
	"Tail Whip",
	"Growl",
	"-",
	"Back"
	}
	local attack=atk(moves)
	print(attack)
  else if selection == 2 then
	break end
  end
end
jag #2
Posted 12 November 2012 - 12:39 AM
Where does the variable "m" come from?


if i==attack then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
Fiery Arcanine #3
Posted 12 November 2012 - 02:26 AM
Oh, I see. I fixed it.

function atk(m)
I forgot to define the M

Topic can close!