Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (VoroneTZ, 7th_zorro), 1,071 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Defines #177113
01/08/08 20:16
01/08/08 20:16
Joined: Jan 2007
Posts: 59
C
Creepinbox Offline OP
Junior Member
Creepinbox  Offline OP
Junior Member
C

Joined: Jan 2007
Posts: 59
Okay.. I've been scripting for a while now .. but I still cant understand the what makes a "define" special .. or what it does at all .. I think maby i have missed something important here ..

Re: Defines [Re: Creepinbox] #177114
01/08/08 22:08
01/08/08 22:08
Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
TripleX Offline
Expert
TripleX  Offline
Expert

Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
Defines are not necssary but can make life easier.
Generally the compiler replaces the first part in the define with the second part of the define BEFORE he starts to compile.

With a define you can for example replace certain numbers with names. Example:

#define max_health 200
if(my.health > max_health) { //CHEATER!!! }
if(my.health > 200) { Thats the same }

As you hopefully see the first if statement is better to read and understand.

You can also write full statements with #defines. E.g.

#define is(obj,flag) (obj.flags & FLAG)

if(is(my,TRANSLUCENT)) { my is transparent }
if(my.flags & TRANSLUCENT) { exactly the same }

Maybe you're interested on how the compiler handles with defines. Before the Compiler starts to compile he checks (code above) if there is any code line in your project that fits to the syntax is(obj,flag). If so he replaces it with (obj.flags & FLAG). After that he starts compiling.

You can refine almost everything (attention, #defines are not always the best solution!!). You could also redfine the name of skills for example.

#define skill[0] health
//..
my.health = 100;
my.skill[0] = 100; //does exactly the same but not as nice to read as the one above


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