Structs and arrays
Displaying 1-5 of 5 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
locke

So I saw in Gun's Pepper II demo that he was using structs and storing them in arrays. Commonly done.

However, when I tried it it wouldn't take for me. First, the code:



#define MAX_SHOTS 10

struct bullet
{
int sx;
int sy;
int active;
};

bullet shots[MAX_SHOTS];

void spawn_shot()
{
int i;

if (player_power > 0 && numShots [less-than] MAX_SHOTS)
{
for (i=0;i[less-than]MAX_SHOTS;i++)
{
if (!shots[i].active) // *** IT FAILS HERE ***
{
shots[i].sx = player_x;
shots[i].sy = player_y - 2;
shots[i].active = 1;
numShots++;
}
}
}
}



("[less-than]" interjected to preserve forum sanity)

Other than issues with coding style, I cannot see why this fails. I get an error that says "expected a "." and got a "["..." -- obviously. It's almost like it thinks "shots" is a single type bullet, instead of an array of type bullet.

I re-formatted it many times, played with the syntax and the variable names enough to know that it's not something like that. I have seen almost exactly the same (types) of lines from the Pepper II source... so I'm hoping someone can look at it and go "err... you missed a ____".

Thanks.

-lok

Posted on 2004-02-23 23:23:51

locke

From vcc_verbose.txt:


Constructing VCCompiler object... Done.
int MAX_SHOTS: offset 0, size 1, initializer: =10
int i_player: offset 1, size 1, initializer: =NewImage(7,7)
int player_x: offset 2, size 1, initializer:
int player_y: offset 3, size 1, initializer:
int player_power: offset 4, size 1, initializer:
int numShots: offset 5, size 1, initializer:
func Autoexec found with 0 args and shit.


Err... the "shots" array is missing... as is the struct. Both of which are defined/initialized immediately after the variable numShots, and immediately before the function Autoexec is defined.

So it should be there, no? Or maybe arrays and/or structs aren't recorded in the verbose log?

Dunno if this means anything.

Thanks.

-lok

"He can fry, but he no can fruck!"

Posted on 2004-02-24 00:17:19

vecna

Couple of notes.
First, the vcc_verbose stuff isn't really significant. Its old code thats only meant for debugging purposes that I never updated to reflect struct definitions and instances, which are stored in a separate lists.

If I modify the code you posted enough for it to compile without the things you left out, it compiles and works fine. So, as you mentioned, the struct code is like identical to other struct code, and it should and does work fine. The problem really has to lay in some of the code you've omitted... possibly a redefinition of a symbol or something that VCC didnt catch? Idunno. you should also make sure youve got the most recent EXE (see thread on the general forum).

Posted on 2004-02-24 02:35:16

locke

Perfect.

That's really all I needed... in the sense that I _thought_ the struct stuff was legit. There isn't much other code, frankly, so knowing it's not the struct stuff helps a lot.

And I'll start ignoring the verbose log... though I think it's a good idea. ;)

Thanks, V.

-lok

Posted on 2004-02-24 07:02:54

locke

Oddly, I had a variable mis-spelt as: shotsNum... once I renamed it to numShots, it compiled like a charm.

Though... I have to admit, an intersecting of sub-strings of variables and variable names seems a little worrysome.

I'm guessing this shouldn't be possible.

-b

Posted on 2004-02-25 01:46:40


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.