Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Do functions have to be in a certain order?

Author
Message
Karxdurik
16
Years of Service
User Offline
Joined: 15th Jun 2008
Location:
Posted: 22nd Jun 2008 22:40
I recently had a problem with some code. Someone suggested to change the order of my functions, and it fixed the problem. I have allot of functions that call upon each other allot, and I don't want to make any mistakes like that again. So can anyone tell me the proper way to order functions and such? I've searched for something like this, but I can't seem to find anything.
Windsept
18
Years of Service
User Offline
Joined: 9th Jun 2006
Location: United States
Posted: 23rd Jun 2008 02:48
The order shouldn't matter unless the different functions depend on variables from other functions.

For example, Function A finds the position of the player and the monster. Function B finds out whether the monster sees the player by using the data from function A. But if in your program you call Function B before Function A nothing will happen because Function B has no data to go on. So in this example, yes the order does matter.

Hopefully I have helped you out some. If not I am sorry.

Windsept
ThinkDigital
19
Years of Service
User Offline
Joined: 18th Aug 2005
Location: A galaxy far, far away...
Posted: 25th Jun 2008 12:42
If you're talking about literal function declarations, they have to be in a part of the code the compiler won't run into (easiest place to put them is after the main loop)

"rm -rf /bin/laden"
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 26th Jun 2008 18:45
That's really weird, the order of the functions shouldn't matter at all, only the order you call them in.

Los Mineros are back in progress!
Karxdurik
16
Years of Service
User Offline
Joined: 15th Jun 2008
Location:
Posted: 28th Jun 2008 00:25 Edited at: 28th Jun 2008 06:33
I know that you can't use variables that aren't global in functions. I know how to pass data into it also. I also know how to make and use functions. This is the code that won't work.

Now, if I change it to
it will work when I call AI_Travel.
ThinkDigital
19
Years of Service
User Offline
Joined: 18th Aug 2005
Location: A galaxy far, far away...
Posted: 30th Jun 2008 23:05
Because you call math_getDist3D in the AI_Travel function, you must define math_getDist3d first or the AI_Travel function will not know what that command is because it has not seen it yet.

"rm -rf /bin/laden"

Login to post a reply

Server time is: 2024-09-27 16:23:50
Your offset time is: 2024-09-27 16:23:50