Problem with arrays
Displaying 1-18 of 18 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Konflaxx

Hello guys,
I've got a problem with an array. I know they have to be global and this array is global

thats a section of the system.vc

int dialogueFont = LoadFont("myfont.png");
int dialogueFontYellow = LoadFont("myfontyellow.png");


#define MAX_TEXT_LINES 4
int TextBoxColor[3];
TextBoxColor[0] = 1;
int TextBoxColorR = 0;
int TextBoxColorG = 0;
int TextBoxColorB = 200;


zoom in

int TextBoxColor[3];
TextBoxColor[0] = 1; //this is the evil line

When i try to compile it the compiler says: "Line 16: Expecting a variable or Function declaration - brace blabla"
As you can see, i don't need the array anymore, but I'd like to know an answer to this problem in order to prevent future problems.

Posted on 2006-08-07 11:30:33 (last edited on 2006-08-07 11:31:45)

Overkill

Yeah you can't assign arrays outside of functions. Wherever you need to initialize an array, you should make a function that's called by AutoExec().


void InitializeTextBox()
{
TextBoxColor[0] = 1;
TextBoxColor[1] = 1;
TextBoxColor[2] = 200;
}

void AutoExec()
{
// ...
InitializeTextBox();
// ...
}

Posted on 2006-08-07 12:07:36

Konflaxx

thank you that helped ma alot

Posted on 2006-08-07 12:59:25

P-ville

I have something like that, but when I try to run the program, I get "system.vc: expecting "[" but got ")" instead"
the only symbol I have on that line is } to close the function

Posted on 2006-10-03 15:14:59

mcgrue

Is this on a program that's been posted? It's easier to spot the problem with some pertinent source.

Posted on 2006-10-04 15:11:29

choris

Quote:Originally posted by P-ville

I have something like that, but when I try to run the program, I get "system.vc: expecting "[" but got ")" instead"
the only symbol I have on that line is } to close the function


It sounds to me like you were trying to use an array without any [ ]'s.
Example.

int arrayVar[6];
your_function(arrayVar);

That would produce that error message I believe.

Posted on 2006-10-04 19:52:52

mcgrue

choris, verge doesn't let you pass an array as a function argument.

Posted on 2006-10-04 20:28:29

choris

Of course not, but if he coded something like that by mistake, verge would give him that error message. And I just checked... and it does.

Posted on 2006-10-04 20:43:05

P-ville

Would I need several functions to assign values to different arrays within a struct, or could it be done with only one function?

Also, it now tells me "invalid argument type" the whole code looks like this

struct unit
{
int unitstat[8];
int unitweapon[12];
int unitability[11];
}

unit player;

void playerunit();
{
player.unitstat[0] = 12
//assign the rest of the values
}

what am I doing wrong?

Posted on 2006-10-05 16:27:24 (last edited on 2006-10-05 16:59:56)

Code

Just a simple syntax error. You've got a semi-colon after the function declaration. :)
void playerunit();

Posted on 2006-10-05 18:12:24 (last edited on 2006-10-05 18:12:56)

P-ville

sorry, that was a mistake, there was no semicolon in the actual code.

Posted on 2006-10-05 22:26:51

Code

Hmm, I ran the code you posted (+ and - a semicolon here or there) and it worked fine for me. Could the problem be elsewhere?

Posted on 2006-10-06 16:20:36

P-ville

It's possible. I currently have all of the different strings in the struct being assigned values in the same function. Is that possible, or does it have to be in different functions?

Posted on 2006-10-06 23:42:08

P-ville

I think the problem is in how I am calling up the function, does anybody have any suggestions?
My current code looks something like this


void AutoExec()
{
Map("Start.map");
Playerunit(player.unit)
}

struct unit
{
int unitstat[8];
int unitweapon[12];
int unitability[11];
}

unit player;

void playerunit();
{
player.unitstat[0] = 12
//assign the rest of the values for unitstat, unitweapon, and unitability
}


the error message says the error is on the line with the final "}" but it claims it is geting ")" and expecting "["
if anybody has any suggestions, I'm running out of ideas for fixing it (hence the reason I'm posting this

Posted on 2006-10-06 23:56:28 (last edited on 2006-10-09 09:47:01)

Overkill


void AutoExec()
{
Map("Start.map");
// Error:
// 1) You don't declare PlayerUnit to take any arguments.
// 2) unit is not a member of the "unit" struct, which player is
// defined to be.
// 3) (Non-fatal) This statement will never be reached, as Map() halts
// execution within functions and jumps to a new map.
Playerunit(player.unit);
}

struct unit
{
int unitstat[8];
int unitweapon[12];
int unitability[11];
}

unit player;

// Error: You have a semi-colon where there should not be one.
void playerunit();
{
// Error: You have neglected to put in a semicolon.
player.unitstat[0] = 12
//assign the rest of the values for unitstat, unitweapon, and unitability
}


I've placed comments above lines of possible errors. Tell me if that helps, and otherwise, package your entire game project into a zip and send it to one of us.

Posted on 2006-10-09 14:38:54

P-ville


void AutoExec()
{
Playerunit();
Map("Start.map");
}

struct unit
{
int unitstat[8];
int unitweapon[12];
int unitability[11];
}

unit player;

void playerunit()
{
player.unitstat[0] = 12;
//assign the rest of the values for unitstat, unitweapon, and unitability
}


still gives the error message

system.vc(line is always the last line of code): Expecting "[" but got ")"

Posted on 2006-10-09 21:09:40

Overkill

Funny, that code segment compiles for me. Are you sure you're not withholding some pieces of your code?

Posted on 2006-10-10 10:56:27

P-ville

That code section did compile. For some reason, another section of the program gave the error at the end of the program.

Posted on 2006-10-10 17:13:03


Displaying 1-18 of 18 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.