Need another pair of eyes
Displaying 1-5 of 5 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
locke

I've been staring at the following code for a little while now, and I can't for the life of me figure out why it fails. The array stuff is very touchy, but I've used arrays this exact same way many times. If you put this code in it's own "system.vc" file and try to compile it, it stops on the line:

choice_y[0] = 25;

...complaining that it was looking for a "," but got a "[". Err... what the heck am I missing?


void show_combat_menu()
{
int num_of_options,selection;

num_of_options = 2; // to be determined by available options...
selection = 0;

int choice_y[num_of_options];
choice_y[0] = 25;
choice_y[1] = 40; // should be done with for loop

rectfill(220,0,320,30,rgb(0,0,0),screen);
PrintString(250,choice_y[0],screen,fnt,"Move");
PrintString(250,choice_y[1],screen,fnt,"Pass");
CircleFill(240,choice_y[selection],2,2,rgb(255,0,0),screen);
ShowPage();

while (!key[SCAN_ENTER])
{
UpdateControls();

if (key[SCAN_UP])
{
selection--;
if (selection num_of_options - 1)
{
selection = 0;
}
}
rectfill(230,0,320,30,rgb(0,0,0),screen);
PrintString(250,choice_y[0],screen,fnt,"Move");
PrintString(250,choice_y[1],screen,fnt,"Pass");
CircleFill(240,choice_y[selection],2,2,rgb(255,0,0),screen);
ShowPage();
}
if (selection == 0)
{
grid_move();
}

// else if ... etc...
}



Am I stepping on a key word?

Did I miss something in there?

My code works fine without this function, so it's just this code.

Thanks!

-l

Posted on 2004-03-05 23:23:06 (last edited on 2004-03-06 00:35:47)

TomT64

You can't declare an array inside a function. It has to be global.

Posted on 2004-03-06 00:20:43

locke

Oh damn.

Are you kidding?

Well, that explains it. Thanks! Can't wait for the docs to come out... ;|

-l

Posted on 2004-03-06 00:25:48

Technetium

I thought it also required that you declare variables at the start of the function, before you can start doing other stuff. Or is that a change from V2?

Posted on 2004-03-06 15:35:20

vecna

Nope, you can declare (non-array, non-struct) variables whenever in v3. It was sort of a natural extension of being able to initialize them.

Posted on 2004-03-06 16:49:02


Displaying 1-5 of 5 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.