Gamestudio Links
Zorro Links
Newest Posts
Bug in train mode, or it seem to me
by jcl. 09/22/26 14:47
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 09/22/26 12:21
Capital slider is not saving in Z12
by Petra. 09/22/26 06:49
Parent/child object
by VoroneTZ. 09/22/26 05:52
Zorro tutorial ideas?
by AndrewAMD. 09/21/26 14:50
Trades during a running bar
by Martin_HH. 09/21/26 12:03
Avoiding pop-up training parameter results
by Martin_HH. 09/16/26 21:31
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 1,418 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
lopezsergio07, mistery, lokkalyansamiti, rahulbuilds, speedx
19237 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 | 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