47 posts
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:
169 posts
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.
2088 posts
Location
South Africa
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
47 posts
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?
1214 posts
Location
The Sammich Kingdom
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.
10 posts
Location
USA - Connecticut
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.