Jump to content




Attempt To Index Field '?' (A Boolean Value)


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

#1 je06

  • Members
  • 44 posts

Posted 30 September 2013 - 02:02 PM

Why am I getting "attempt to index field '?' (a boolean value)"?

What I'm trying to do is create a program that can do ray tracing.
Code
Spoiler
What my code is meant to do is create a 'ray' that keeps going until it ether hits something
or when't as far as its meant to go.

My code is working until it read 'world[a][b][c]' then it gives me the error above.

If someone else posted a problem just like this please tell me because I looked for a long time.

P.S. It is hard coded to work with a computer screen only for a reason

#2 BigTwisty

  • Members
  • 106 posts

Posted 30 September 2013 - 02:51 PM

Couple of problems:
1:
for c=sizeZmin, sizeYmax do
should be:
for c=sizeZmin, sizeZmax do

2. There are several places where world is referenced with 4 sub tables, but it only seems to be generated with 3.

3. You defined importModel with 2 arguments, but are calling it with 5. The last 3 arguments are being ignored.

Those are just the few I found on a quick scan. If you fix those and it still doesn't work, we can look more in depth.

#3 je06

  • Members
  • 44 posts

Posted 25 October 2013 - 08:49 PM

Re-wrote the code. My new code works fine except the function where it calculates all the different ray paths. Now it thinks blue is in every table or something like that.
New Code
Spoiler

If you can please fix my code.

P.S. Sorry it took a while to write back.

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 26 October 2013 - 04:57 AM

I'm not going to pretend to understand what this is supposed to do (hence I've no idea how to fix it to do exactly what you want; it looks like it wants to be a 3D engine but I'm not entirely sure), though I can tell you what it does do:

1) "f" is dumped into world["testObject"]. Note that line 73 sets f[1][1][1] to the colour blue, hence world["testObject"][1][1][1] is also blue.
2) The screen function is called by line 78. x, y and z are each set to 1 at this point.
3) Line 49 (which calls newRay) will be processed a number of times, but every single time, x, y and z will still each be 1.
4) Lines 19-20 copy the contents of x, y and z into cX, cY and cZ.
5) Lines 23-25 copy the (unchanged) contents of cX, cY and cZ back into x, y and z.
6) The newRay function always returns world["testObject"][x][y][z] at line 27.
7) Since x, y and z will still, under all circumstances, each be one, that means f[1][1][1] (the colour blue) is the only colour that gets dumped into tablea by the newRay function called at line 49.

Also note that when newRay returns, execution of that function stops. The loop started on line 22 only ever gets halfway through one iteration - it then breaks off because the function has returned an answer.

Edit:

I guess that you want line 27 to check what world["testObject"][cX][cY][cZ] is, and return it if non-nil. You'd then return nil if the loop initiated on line 22 finished up without finding a "hit". I've not tested this nor thought through your formulas.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users