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

Function Error.

Started by Popeye, 16 April 2013 - 04:41 AM
Popeye #1
Posted 16 April 2013 - 06:41 AM
Hello Everyone,

Today I was Experimenting with Function's. And got an Error.

Error: Function:7: attempt to call nil

Code:
SadKingBilly #2
Posted 16 April 2013 - 06:42 AM
You call your function before you define it. Just rearrange the code blocks so that the function definition is before the function call.
remiX #3
Posted 16 April 2013 - 06:45 AM
Think of it this way, when you phone a person, you need to call them first to actually speak to them :P/>, here you need to define a function first before calling them

Haha xD

Just remember: Define your functions at the top of the program
Popeye #4
Posted 16 April 2013 - 07:20 AM
You call your function before you define it. Just rearrange the code blocks so that the function definition is before the function call.

So.. what you're Saying is that I have to Put the Function before the If?
Sammich Lord #5
Posted 16 April 2013 - 07:23 AM
You call your function before you define it. Just rearrange the code blocks so that the function definition is before the function call.

So.. what you're Saying is that I have to Put the Function before the If?
Yep.
majesty2450 #6
Posted 16 April 2013 - 07:35 AM
Code executes from a file from top to bottom. In order to call a function or access a variable it needs to have been executed into memory first. It cannot execute what has not been executed yet. The primary keywords such as function, print, local, etc… have already been executed because they are in the api. You are able to use them because they have been executed. If they weren't in the API, you would get an error because they would not have been executed and the computer would not know what they are.
This is just a way to visualize it and is not exactly what happens.