145 posts
Location
the vast cosmos of my mind; binary!
Posted 10 July 2012 - 06:39 PM
hey guys when ever i use the function command i get ten as my output like so could you please tell me what i am doing wrong s o i dont run into this problem again. oh and it also happens when i am using while true do
like soo
function n()
n()
———————-
>????
10
>
286 posts
Location
Bonn Germany
Posted 10 July 2012 - 08:19 PM
function n()
is no real function you have to at least put an end there. All the code between the headline of the function (function n()) and the end will be executed when calling the function
145 posts
Location
the vast cosmos of my mind; binary!
Posted 10 July 2012 - 09:35 PM
WHANKS THAT HELPED
286 posts
Location
Bonn Germany
Posted 10 July 2012 - 10:20 PM
You're welcome. By the way it's the same for all loops and if constructions.
1 posts
Posted 22 December 2012 - 12:05 AM
Little more in-depth:
A function has a start and a end (same for a loop).
function MyFunction() –Start
end –End
Here's some simple loops
while true do –Won't end until told to (reason why it can freeze things)
sleep(1) –while true do will freeze your ComputerCraft Computer/turtle if it does not have a wait
end
repeat –This loop doesn't end until it reaches a certain point
sleep(5)
print("Hello World!")
until 1==2 –I have made the loop to end if 1 is equal to 2.. which will never happen so the loop is limitless
NUMBER = 2 – Our number
for i=1,NUMBER do –This loop will count up until it reaches our number then will stop.
end