#define

Non-platform specific questions.

Postby Troodon » Sat Feb 24, 2007 1:57 pm

Ok, thanks. :oops: :D

I don't want to sound idiot, but is the #define making a normal variable?
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby makslane » Sat Feb 24, 2007 2:17 pm

The #define just create a 'replace' in the code.
If need to use some value, like 3.1416 in your code, you can make a define, like this:

#define PI 3.1416

And just use PI in the code.
Please, refer to some C docs.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Troodon » Sat Feb 24, 2007 2:20 pm

Wow, thanks!
I haven't read any C docs, only the GE documentation. Maybe I should start learning C...
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby Fuzzy » Sat Feb 24, 2007 10:43 pm

Yes, define is more than storage for values of strings. You can use it to store portions of code. That code will go uncompiled at first..

#define HEAL Hp+amount, MaxHP

then later in code...

amount = rand(10);
hp = min(HEAL);

you can see that it can act somewhat like a function, without the overhead of the function. It stores the formula and nothing more. You dont have to remember what arguments to pass it. You could also wrap the min() around the contents of HEAL.

Note that convention says use capital letters for define labels, and that the line is not normally appended with ; but it is legal.

one interesting use is to shorten key words...

#define GaAiC getAllActorsInCollision
#define EA "Event Actor"
later in code...

GaAiC(EA,&num);

thats kinda silly, but shows how you can compress your code. If you use certain long key words repeatedly, you can actually shorten up your code considerably.

From my experiments, it extends to the compiled program too. however, you might find that it slows things down a bit. Makslane will know better than I.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby Sgt. Sparky » Sun Feb 25, 2007 12:04 am

I still like it! :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Troodon » Sun Feb 25, 2007 11:52 am

Ok, thanks!
:D Is there any place (in web) where I could find that kind of C script things?

For example what's the '|' doing?
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby Sgt. Sparky » Sun Feb 25, 2007 11:59 pm

that is a setance end :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Troodon » Mon Feb 26, 2007 1:38 pm

Sentence end?
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby Sgt. Sparky » Thu Mar 01, 2007 1:28 pm

yup.
that way it does not get glitchy :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby UltimatHedgehog » Thu Mar 01, 2007 8:30 pm

how do you type '|' it's not on the keyboard
Image
I always thought Hell would be a giant load screen that goes on for eternity, then one day, eons later, it would end, only to reveal a slightly different loading screen.
User avatar
UltimatHedgehog
 
Posts: 325
Joined: Fri Jan 19, 2007 1:48 pm
Location: http://downloads.khinsider.com/?u=112542 plz click
Score: 10 Give a positive score

Postby Kodo » Thu Mar 01, 2007 8:41 pm

look at the bottom left of your keyboard, hold down the left shift and press the key next to it (backslash). Least that's what it is on a UK keyboard.
Inogames: http://www.inogames.com iOS gaming
Firetop Adventure (app store): http://itunes.apple.com/us/app/firetop- ... ?mt=8&ls=1
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score

Postby UltimatHedgehog » Thu Mar 01, 2007 10:08 pm

thats capital Z there is one that is 2 lines one on top one on bottom looks just like | but with a space in the middle but thats the right one

its only a | in certain fonts though
Image
I always thought Hell would be a giant load screen that goes on for eternity, then one day, eons later, it would end, only to reveal a slightly different loading screen.
User avatar
UltimatHedgehog
 
Posts: 325
Joined: Fri Jan 19, 2007 1:48 pm
Location: http://downloads.khinsider.com/?u=112542 plz click
Score: 10 Give a positive score

Postby Kodo » Thu Mar 01, 2007 10:26 pm

thats capital Z

That'll be why I said "on a UK keyboard", keyboard layouts vary slightly from country to country, on mine the | key is next to the Left Shift ;)
Inogames: http://www.inogames.com iOS gaming
Firetop Adventure (app store): http://itunes.apple.com/us/app/firetop- ... ?mt=8&ls=1
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score

Postby Game A Gogo » Thu Mar 01, 2007 11:39 pm

in Canada keyboard (Should be similar to U.S.A.) English, its Shift and Back slash (Right above the Enter), and for French, its should be Alt Gr and 6
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby UltimatHedgehog » Fri Mar 02, 2007 12:39 am

what you said about the canadian is on mine so yes youre right its like usa keyboard
Image
I always thought Hell would be a giant load screen that goes on for eternity, then one day, eons later, it would end, only to reveal a slightly different loading screen.
User avatar
UltimatHedgehog
 
Posts: 325
Joined: Fri Jan 19, 2007 1:48 pm
Location: http://downloads.khinsider.com/?u=112542 plz click
Score: 10 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest