i have a memeber function in a struct, and when i wright it out:
static function Player_Settings::SetControls(int left, int right, int up, int down, int shooting)
{
this.left = left;
this.right = right;
.......
}
i noticed that <this.> is not available, is there a equivalent to achieve this??
static functions do not have a "this" pointer, since there is no instance to reference.
It's the basic idea of a static function. If the function always exists then there is no instance of the struct to access data members of. If you want to access the data then there has to be an instance of the struct in existance. Just get rid of that static keyword.
First:
A "this"-pointer would reference to an object of the struct. Since your function is static that function wouldn't be able to reference a particular object by "this".
Second:
To my knowledge it is (so far) not possible to create new objects of a struct in AGS. Therefore a non-static function in a struct would have no meaning since you won't be able to call it.
My recommendation is therefore that you have two global variables that you change instead from this static function.
And by the way, CJ: A new-command would have been tremendous! But probably hell for you since it would involve dynamic memory handling and all that crap.
Quote from: fovmester on Mon 06/02/2006 10:46:57
To my knowledge it is (so far) not possible to create new objects of a struct in AGS. Therefore a non-static function in a struct would have no meaning since you won't be able to call it.
You can declare variables that are structs and arrays of them. However, you can't do so
dynamically. And of course you can call non-static functions in structs.
struct a { int b; import function setb(int b); };
a b;
b.setb(4);
ok, thx
is it possible to declare a static variable in structs?
cause i need values only once for an array of structs.
example:
struct Enemies{
Ã, // Sprites
Ã, Overlay* enemy_graphics;
Ã, int enemy_sprites;
Ã, int width;Ã, // enemies sprite proberties
Ã, int height;
..
..
stactic int all_enemies;
static int enemy_type;
static int amount_of_enemies_per_type;
};
if not, i guess i need another struct, where i store values who
dont change for the complete game
No static variables yet. (http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=543)
Workaround - Make them global. It gets the job done...and if you name them something like Enemies_all_enemies then it would work essentially the same only with an underscore ('_') in place of the period ('.').
Also, rather than having an array of structs each with an overlay, etc, why not have:
struct Enemies{
// Sprites
Overlay* enemy_graphics[MAX_ENEMIES];
int enemy_sprites[MAX_ENEMIES];
int width[MAX_ENEMIES]; // enemies sprite proberties
int height[MAX_ENEMIES];
..
..
int all_enemies;
int enemy_type;
int amount_of_enemies_per_type;
};
cause for me it feels more "natural" and makes things easier.
assuming i have in the struct, something like:
Ã, Overlay* shoot_graphic[MAX_SHOOTS];
which i have in the player struct, then it became more complicated,
cause then i need
Overlay* shoot_graphic[MAX_ENEMIES*MAX_SHOOTS]; for example
there allways a lot of possible ways.
and when the module ist published, i hope that
we discuss the downsides of it (and there are a lot thats for sure)
to improve it.
Well, no, because you can only have 20 overlays at once anyway...
well, this is the biggest problem, so i hope for future increase of this limit.
unfortunatly it was to late to stop my work, as i recognized this limit.
The only way to display more than, say, 50 objects at once is to do it by hand.
pseudo code:
repeatedly_execute() {
Ã, calculate positions and appropriate sprite slots;
Ã, draw background; (get rid of drawn objects)
Ã, draw objects;
}
The order is important; as the calculations take up cpu time, they should be processed right after everything is drawn in place and before the screen is redrawn to avoid flickering.
It shouldn't be that hard to rewrite your overlay-routines to use DynamicSprites instead.
thanks, good idea.
ill look into it, after finishing the inital module version.