4 posts
Posted 28 December 2012 - 03:39 AM
Okay so i have been trying to get the turtles to work by making floppys and making the programs ingame making lua files and putting them in the right folders "ComputerCraft1.48.zip\lua\rom\apis" i think its the right one anyway and when i finally get past all the errors that im getting when i making the program i end up with some weird error when trying to start it.
When i use the turtle i go lua test.test2 test being the name of the file, the error i get is: "function: 7f1a24aa" and the numbers are random for each turtle.
function test2()
turtle.refuel(2)
turtle.forward()
turtle.up()
turtle.up()
end
when i try the program i have on the floppy or made on the turtle nothing happens and im not forgetting fuel, i might be doing something wrong in the programming stuff but i hope someone can help me.
(im very new to the whole programming thing) :)/>
7508 posts
Location
Australia
Posted 28 December 2012 - 03:55 AM
sounds like you are doing this in the Lua program on the terminals… type test.test2() instead
the reason that it says function: random numbers is not actually an error, it is doing a tostring( ) on the function and actually telling you its reference/location in memory, hence the numbers differing each time :)/> when this is used in programming intentionally it is called function pointers. :)/>
hope this helps :)/>
1604 posts
Posted 28 December 2012 - 03:57 AM
Try actually calling the function:
test.test2()
brackets are important, otherwise it will just return the function (the actual function, not it's result).
When you run it, nothing happens because you are not calling the function. Try adding:
test2()
at the end of the file.
Also, if you want to make a program, don't put it in the apis directory, that's for apis. Place it in the programs directory or the root of the computer/turtle.
7508 posts
Location
Australia
Posted 28 December 2012 - 03:59 AM
brackets are important, otherwise it will just return the function (the actual function, not it's result).
It actually returns the reference/location in memory to the function, not the function itself.
4 posts
Posted 28 December 2012 - 04:13 AM
works now! thanks guys :)/>
4 posts
Posted 28 December 2012 - 04:16 AM
sounds like you are doing this in the Lua program on the terminals… type test.test2() instead
the reason that it says function: random numbers is not actually an error, it is doing a tostring( ) on the function and actually telling you its reference/location in memory, hence the numbers differing each time :)/> when this is used in programming intentionally it is called function pointers. :)/>
hope this helps :)/>
the thing with the () worked like a charm but i still dont understand why the programs isnt working when i program them directly to the turtle or on a floppy disk, any clue? :P/>
1604 posts
Posted 28 December 2012 - 05:27 AM
brackets are important, otherwise it will just return the function (the actual function, not it's result).
It actually returns the reference/location in memory to the function, not the function itself.
That's what I meant, just trying to make it clearer for him :P/>
sounds like you are doing this in the Lua program on the terminals… type test.test2() instead
the reason that it says function: random numbers is not actually an error, it is doing a tostring( ) on the function and actually telling you its reference/location in memory, hence the numbers differing each time :)/> when this is used in programming intentionally it is called function pointers. :)/>
hope this helps :)/>
the thing with the () worked like a charm but i still dont understand why the programs isnt working when i program them directly to the turtle or on a floppy disk, any clue? :P/>
Like I said before, you need to call the function in the program. It should be something like:
function test2()
-- do something
end
test2() -- call the function so it actually does something
4 posts
Posted 28 December 2012 - 05:48 AM
oh okay thanks :)/>