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

Bug for no reason?

Started by Ziriee, 26 January 2013 - 07:09 AM
Ziriee #1
Posted 26 January 2013 - 08:09 AM
Spoiler

function updateNPC()
  if npcmode == "dumb" then
    turn = math.random(1,4)
if (turn == 1) and ((map[npcpos-9] == "-") or (map[npcpos-9] == "d" and door)) then
   npcpos = npcpos-9
   npcy = npcy-1
elseif (turn == 2) and ((map[npcpos+9] == "-") or (map[npcpos+9] == "d" and door)) then
   npcpos = npcpos+9
   npcy = npcy+1
elseif (turn == 3) and ((map[npcpos-1] == "-") or (map[npcpos-1] == "d" and door)) then
   npcpos = npcpos-1
   npcx = npcx-1
elseif (turn == 4) and ((map[npcpos+1] == "-") or (map[npcpos+1] == "d" and door)) then
   npcpos = npcpos+1
   npcx = npcx+1
end
  elseif npcmode == "stalk" then
    if npcy > chary then
   if map[npcpos-9] == "-" or (map[npcpos-9] == "d" and door) then
	 npcpos = npcpos-9
  npcy = npcy-1
   elseif map[npcpos+1] == "-" or (map[npcpos+1] == "d" and door) then
	 npcpos = npcpos+1
  npcx = npcx+1
   elseif map[npcpos-1] == "-" or (map[npcpos-1] == "d" and door) then
	 npcpos = npcpos-1
  npcx = npcx-1
   end
elseif npcy < chary then
   if map[npcpos+9] == "-" or (map[npcpos+9] == "d" and door) then
	 npcpos = npcpos+9
  npcy = npcy+1
   elseif map[npcpos+1] == "-" or (map[npcpo+1] == "d" and door) then
	 npcpos = npcpos+1
  npcx = npcx+1
   elseif map[npcpos-1] == "-" or (map[npcpos-1] == "d" and door) then
	 npcpos = npcpos-1
  npcx = npcx-1
   end
elseif npcx > charx then
   if map[npcpos-1] == "-" or (map[npcpos-1] == "d" and door) then
	 npcpos = npcpos-1
  npcx = npcx-1
   elseif map[npcpos-9] == "-" or (map[npcpos-9] == "d" and door) then
	 npcpos = npcpos-9
  npcy = npcy-1
   elseif map[npcpos+9] == "-" or (map[npcpos+9] == "d" and door) then
	 npcpos = npcpos+9
  npcy = npcy+1
   end
elseif npcx < charx then
   if map[npcpos+1] == "-" or (map[npcpos+1] == "d" and door) then
	 npcpos = npcpos+1
  npcx = npcx+1
   elseif map[npcpos-9] == "-" or (map[npcpos-9] == "d" and door) then
	 npcpos = npcpos-9
  npcy = npcy-1
   elseif map[npcpos+9] == "-" or (map[npcpos+9] == "d" and door) then
	 npcpos = npcpos-9
  npcy = npcy+1
   end
end
  end
end


Full code:
http://pastebin.com/pmSyttDX

ANY HELP POSSIBLE??
Lyqyd #2
Posted 26 January 2013 - 08:14 AM
You need to initialize your variables to something before you can perform mathematical operations on them.
Ziriee #3
Posted 26 January 2013 - 08:16 AM
That's in the drawNPC() function
cmurtheepic #4
Posted 26 January 2013 - 08:17 AM
it is having trouble finding the variable "door" that is the problem
Ziriee #5
Posted 26 January 2013 - 08:19 AM
That's at the start of the whole script. "door = false". Just look at the whole code in pastebin.
Lyqyd #6
Posted 26 January 2013 - 08:25 AM
That's in the drawNPC() function

Try putting empty local declarations at the top of the script for all of the variables declared there.
LBPHacker #7
Posted 26 January 2013 - 08:32 AM
Try
map[npcpos+1]
instead of
map[npcpo+1]
Ziriee #8
Posted 26 January 2013 - 08:50 AM
Try
map[npcpos+1]
instead of
map[npcpo+1]
Perfect.