Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
7 registered members (3run, miwok, AndrewAMD, Quad, TipmyPip, fairtrader, 1 invisible), 637 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
definition bevor and after calling ?!? #285651
08/19/09 14:14
08/19/09 14:14
Joined: Mar 2007
Posts: 1,852
A
alpha_strike Offline OP
Serious User
alpha_strike  Offline OP
Serious User
A

Joined: Mar 2007
Posts: 1,852
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?

Re: definition bevor and after calling ?!? [Re: alpha_strike] #285663
08/19/09 15:11
08/19/09 15:11
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
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.

Re: definition bevor and after calling ?!? [Re: MMike] #285667
08/19/09 15:34
08/19/09 15:34
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
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:
Code:
// 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:
Code:
// zombie.c

// include required header files
#include "zombie.h"
#include "player.h"

/* FUNCTION IMPLEMENTATIONS HERE */



Just as an example.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1