Posted By: alpha_strike
definition bevor and after calling ?!? - 08/19/09 14:14
stupid, but I canīt find it in the manual.
C-Script... every function can be called from every script, even if the function stands after the calling function.
Lite-C... you can only call a function, when written bevor the call.
But I remember, there is a possibility that the engine read all functions bevor starting the game...
can anyone help?
Posted By: MMike
Re: definition bevor and after calling ?!? - 08/19/09 15:11
bevor? what dont you mean before?
Well about your problem.
of course allt he functions are called before start the game, since they are " compiled" and check for errors...
your function must be defined no matter what, before the calling process, otherwise, its impossible to call something that does not exists.
Now you can call functions that are core functions, and contains the function itself, after the call, if and only you did prototype it first. Example:
function main() { hello(); } // this wont work, your calling something that
doesn't exist before the call of the hello() function.
function hello(){ error("HELLO"); }
--------------
but.. this will work, if you (put the function on the top like:)
function hello(){ error("HELLO"); }
function main() { hello(); } // this will work, because the hello function is defined already. and you can call its name.
-------- OR --- by prototyping the function which is this..
function hello();
function main() { hello(); }
function hello(){ error("HELLO"); }
in this last case:
the main function that starts the game, call the function hello(), defined above, but that functions as you can see contains no code, or functions or methods. its just the definition name , so the engine now knows there is somewhere a function called hello().
in this case, its right after the call.
Dont forget, that calling a prototyped function, will require to construct the functional function with code, in this example the core function which is error("hello"); otherwise there was nothing to do, and no need to define such function.
I hope you understood.
Posted By: Saturnus
Re: definition bevor and after calling ?!? - 08/19/09 15:34
You could make a header file that contains all relevant function prototypes and include it whereever the functions are needed. If your code is divided in several modules (e.g. player.c, zombie.c ...) you can make a header file for each module.
For example, the zombie header file:
// zombie.h
#ifndef ZOMBIE_H
#define ZOMBIE_H
void zombie_attack(ENTITY *zombie ENTITY *target);
void zombie_die(ENTITY *zombie);
...
#endif
And the appropriate zombie.c-file:
// zombie.c
// include required header files
#include "zombie.h"
#include "player.h"
/* FUNCTION IMPLEMENTATIONS HERE */
Just as an example.