Jump to content




[Lua][Error] I need help finding out the error im getting for this a* demo


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

#1 columna1

  • Members
  • 65 posts

Posted 13 January 2013 - 08:14 PM

Ok first of all i know my code is sloppy (very sloppy) and am apologising now for it but this is just a proof of concept
This program is NO WHERE NEAR finished and will not do anything if it is in good shape as it is
i know there are other methods i can do to make this but that is not what im focusing on so please if you can just help me here

also I know that there are probably many errors in this code some of which are just plane obvious but that is mostly me
being an idiot and forgetting syntax but anyways here is my problem

I am making a demo and I have run into a problem...
I have tested this in another program so i know that is should work no problems but it wont work for me here

The error I am getting is this 85: index expected, got nil
I have scanned the code many times and i am aggravated at the fact it is doing this and here is my code

Spoiler

Anyways if you could tell me what im doing wrong I would appreciate it sooooooooo much and be ultimately grateful
thank you

#2 RunasSudo-AWOLindefinitely

  • Signature Abuser
  • 249 posts
  • Location/dev/earth1aus5

Posted 13 January 2013 - 08:17 PM

At a glance, it sounds like either, cell, x, y, or cell[x] is nil. Are you sure all of your for loops and everything are correct?

#3 columna1

  • Members
  • 65 posts

Posted 13 January 2013 - 08:21 PM

Im pretty sure that the way im defining it in the for loop:

81:	for y = 1,w do -- for each cell do
82:	   cell[y] = {}
83:	   stringl = filel.readLine()
84:	   for x = 1,h do
85:		 cell[x][y] = {}
86:		 --calculate heuristic
87:		 dx = math.abs(ex - x)
88:		 dy = math.abs(ey - y)
89:		 h = dx + dy
90:		 cell[x][y].h = h-1
91:		 ce = stringl:sub(y,y)
92:		 cell[x][y].type = gettype(ce)
93:	   end
94:	 end

would define cell[x] first then it would define
cell[x][y] as a table
so that i could use it almost as an object with a 2d identifier

Also if you want i could post the code without the lines numbered
and i have defined cell to as a table

#4 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 08:53 PM

View Postcolumna1, on 13 January 2013 - 08:21 PM, said:

Im pretty sure that the way im defining it in the for loop:

81:	for y = 1,w do -- for each cell do
82:	   cell[y] = {}
83:	   stringl = filel.readLine()
84:	   for x = 1,h do
85:		 cell[x][y] = {}
86:		 --calculate heuristic
87:		 dx = math.abs(ex - x)
88:		 dy = math.abs(ey - y)
89:		 h = dx + dy
90:		 cell[x][y].h = h-1
91:		 ce = stringl:sub(y,y)
92:		 cell[x][y].type = gettype(ce)
93:	   end
94:	 end

would define cell[x] first then it would define
cell[x][y] as a table
so that i could use it almost as an object with a 2d identifier

Also if you want i could post the code without the lines numbered
and i have defined cell to as a table

cell[y] = {}, when y is 1, puts an empty table at cell[1].
then you go into the x loop.
when x = 1, cell[1][1] = {} works fine because you created that empty table at cell[1].
But the next time through the for loop, you try to access cell[2][1] which doesn't exist...

#5 columna1

  • Members
  • 65 posts

Posted 13 January 2013 - 09:23 PM

well derp i feel stupid now XD
hmm
now all i need to do is figure out a way to get around that...

#6 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 09:32 PM

you should be able to just switch the for loops. for x = 1, w .... for y = 1, h...

#7 columna1

  • Members
  • 65 posts

Posted 13 January 2013 - 10:47 PM

but then x and y in cells ends up backwards so do i have to reverse everything that calls it or can i reverse that still somehow?

#8 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 10:49 PM

as far as i can tell, reverse everything that calls it.

#9 columna1

  • Members
  • 65 posts

Posted 13 January 2013 - 11:02 PM

That makes it confusing as hell is there any way to reverse cell so that it is not backwards?

#10 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 11:07 PM

wait i think I was confused to your last question there. What I was saying originally was to change it to:

[code]
81: for x = 1,h do -- for each cell do
82: cell[x] = {}
83: stringl = filel.readLine()
84: for y = 1,w do
85: cell[x][y] = {}
86: --calculate heuristic
87: dx = math.abs(ex - x)
88: dy = math.abs(ey - y)
89: h = dx + dy
90: cell[x][y].h = h-1
91: ce = stringl:sub(y,y)
92: cell[x][y].type = gettype(ce)
93: end
94: end
[/code]
edit - can't figure out formating with this copied and pasted. sorry all you formatting gods :P

#11 columna1

  • Members
  • 65 posts

Posted 13 January 2013 - 11:24 PM

thats what i did
that still makes it umm
sideways i think
anyways its still backward and it needs to be reversed
im reading from a file and adding a cell for each "pixel" if you will
x has to be the width and y has to be the height otherwise it wont work
in this case you are making x the height and y the width
which is a problem because you can only read lines with the file api
not colums like this
sssssssss
wwwwwww
sssssssss
wwwwwww
sssssssss
if you read it that way then it will end up:
cell[1][2] = S
instead of W like i want it to be
as in first char on the second line
you get the second char on the first line

#12 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 11:36 PM

oh, your original loops had y associated with the width and x with the height... i thought that was strange but just kept that for you.
basically if it doesn't do what you want it to do, you'll probably have to re-write it to properly fit the structure you want...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users