Jump to content




Table does not get created


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

#1 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 13 June 2013 - 09:32 AM

Hello dear programmers!

Today I was working on my GUIbuilder and figured out that my term API overwrite was not working as I was expecting.
I came to the conclusion, that a table doesnt get created. The program is starting to complain at line 69, Im assuming it will also error on lines 70 and 71.

I create the table via a metatable, wich you can see on line 16. I immediatly create the table, and that does work (It is not starting to complain). But when I call line 69, it says: "attempt to call nil"

I had this error for quite a few days now, and I cant seem to figure out the problem. Also, the file.writeLine's are for debugging.

For those who like to count:
Spoiler

Or if you dont feel like counting: http://pastebin.com/hzQfHndT

Thank you very much in advance!

#2 GopherAtl

  • Members
  • 888 posts

Posted 13 June 2013 - 09:53 AM

at line 18, you replace the [x] table with an empty table inside the y loop. screen[layer.layers][x] should be initialized in the x loop, before entering the y loop; as it is, the final table will have [x] tables containing only the last y value.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 13 June 2013 - 09:55 AM

BTW this will never be run as term.native always exists, without term.native the term api wouldn't work, term.native is what actually renders to the device.
if not term.native then
  term.native = {}
  term.native.setBackgroundColour = term.setBackgroundColour
  term.native.setTextColour = term.setTextColour
  term.native.write = term.write
end


#4 GopherAtl

  • Members
  • 888 posts

Posted 13 June 2013 - 10:02 AM

yeah, was about to come back and point that out, tob. In fact, it's not at all clear to me how this code works at all, after looking more closely at it. w and h don't seem to be defined, so the initialization loop should error out at line 16.

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 13 June 2013 - 10:04 AM

oh yeh, it actually does, to get it to run I had to add
local w, h = term.getSize()
at the top of the code, I didn't even think of saying that :P

#6 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 13 June 2013 - 12:27 PM

View PostGopherAtl, on 13 June 2013 - 09:53 AM, said:

at line 18, you replace the [x] table with an empty table inside the y loop. screen[layer.layers][x] should be initialized in the x loop, before entering the y loop; as it is, the final table will have [x] tables containing only the last y value.
I knew it was a silly mistake! Thank you very much! :D

View Posttheoriginalbit, on 13 June 2013 - 09:55 AM, said:

BTW this will never be run as term.native always exists, without term.native the term api wouldn't work, term.native is what actually renders to the device.
if not term.native then
  term.native = {}
  term.native.setBackgroundColour = term.setBackgroundColour
  term.native.setTextColour = term.setTextColour
  term.native.write = term.write
end
Hmm.. Good point. Never knew that it actually renders the screen. Thank you! :)

View PostGopherAtl, on 13 June 2013 - 10:02 AM, said:

yeah, was about to come back and point that out, tob. In fact, it's not at all clear to me how this code works at all, after looking more closely at it. w and h don't seem to be defined, so the initialization loop should error out at line 16.
I should have put in that part. I figured it was not in the whole code, only in this part where it was erroring. On the top I have so called 'global variables'





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users