a fundamental question about global code

Non-platform specific questions.

a fundamental question about global code

Postby sonicfire » Sun May 29, 2011 4:50 pm

so, when i do something simple like
Code: Select all
int field[8][8]


in the global code area and give it a name like "startup", is THIS 2d int array then really global
and accessable by every actor in my game ??
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: a fundamental question about global code

Postby jimmynewguy » Sun May 29, 2011 5:19 pm

yes, but don't forget to end the line with a semi colon and save the global code
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: a fundamental question about global code

Postby lcl » Sun May 29, 2011 9:48 pm

But note that it will be global only if it's not in any function code.
Declarations must be the first things in Global Code.

Like this:
Code: Select all
int myVar[10][10]; //This will be global

void move(int amount)
{
    x += amount;
}


Not this:
Code: Select all
void move(int amount)
{
    int myVar[10][10]; //This will not be global, it will be the functions own variable
    x += amount;
}


:)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: a fundamental question about global code

Postby sonicfire » Mon May 30, 2011 3:18 pm

thanks!
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest