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

function via string with table as arg

Started by Lupus590, 14 February 2018 - 09:27 PM
Lupus590 #1
Posted 14 February 2018 - 10:27 PM
Running the program through apmanzilla's tace program gives:

string:67: attempt to call nil
	at test:501
	at test:512

The function is loaded as a string so that it can be saved to a file for 'child' turtles, this string starts at line 188.

Full code on pastebin, including a large bit which is currently commented out due to seperate bugs (feel free to help here too).

If you run the code you will want to put in the turtle:
  • 2 stacks of cobble
  • a good amount of coal or charcoal (either work), it will ask for more if it runs out
  • The program has more requirments but that is the minimum for this testing
You will also want to put the turtle in a 9x9 box, height doesn't matter, just make sure that the turtle is below the box's top.
Edited on 14 February 2018 - 09:32 PM
SquidDev #2
Posted 14 February 2018 - 10:36 PM
From what I can tell (I haven't run the file, just opened it in an editor), line 67 of gotoSource is checkFuel(). As this is only defined in cobbleGenSource, it'll be nil when loading gotoSource on line 262.
Lupus590 #3
Posted 15 February 2018 - 01:03 PM
The error line number of the first line "string:67" makes more sence now, it was complaining about line 67 of the string like it was a serperate file.

I haven't made a fix yet, need to rethink the functions and such.
Lupus590 #4
Posted 15 February 2018 - 05:10 PM
I'm struggling to come up with a fix for this which I would call elegent. I only have one idea so far and it would require a rewrite of every bit of code which uses the failing function, currently I'm thinking of lumping all of the required functions into a table in the string, I'm not entirely sure that this would work.

Idea I got while writing the above ('cos that's how my brain works apparently):
Another option is to write the functions to a seperate file and load them like an API. (so the program comes with it's required APIs and self extracts them). I would prefere to keep all of my code in one file through.

From what I can tell (I haven't run the file, just opened it in an editor), line 67 of gotoSource is checkFuel(). As this is only defined in cobbleGenSource, it'll be nil when loading gotoSource on line 262.

There is another check fuel (compatable but different I think) on line 109

Also, due to how goToSource is written, won't it error on line 717?
Edited on 15 February 2018 - 04:12 PM
Lupus590 #5
Posted 15 February 2018 - 05:38 PM
If you get stuck, have a shower.

Nested function via string concatination.

Yes I had a shower, and as soon as the water hit my hair I had a eureka moment.
Edited on 15 February 2018 - 04:40 PM
Saldor010 #6
Posted 15 February 2018 - 06:18 PM
If you get stuck, have a shower.

Nested function via string concatination.

Yes I had a shower, and as soon as the water hit my hair I had a eureka moment.

Hey, maybe you should write a tutorial on getting unstuck from problems? Glad you figured it out though.
Lupus590 #7
Posted 15 February 2018 - 06:35 PM
Hey, maybe you should write a tutorial on getting unstuck from problems? Glad you figured it out though.

Kinda alread have: http://www.computercraft.info/forums2/index.php?/topic/25484-making-complex-program-goals-manageable/

Although, I could add a section about allowing 'the back burner' to solve problems.
Lupus590 #8
Posted 17 February 2018 - 09:30 PM
Even better way: https://www.lua.org/...l.html#pdf-load

EDIT: IT WORKS!!!

now to fix the other issues, but I think I can manage those

Edit 2: now I'm seeing signs of dependency hell :(/>
Edited on 17 February 2018 - 08:45 PM