- Joined
- Dec 31, 2006
- Messages
- 2,216
I dunno if anyone else have made a thread like this, but here goes.
As most of you know you can create structs in Galaxy. Not vJASS structs, but C structs. These structs are like this:
Those of you who do C programming know you can't make constructors, but you can cheat >
By default all members will have their default values, i.e ints are 0, fixed are 0., units are null, etc.
When you destroy one of them just do like this:
Now you're probably wondering "What's the pointer for?". Well, since we can't do "WAI = WAI[Total]" we must then just point to the one at the end of the list. "What about that boolean?", well, to prevent doing stuff to one struct twice or trice or whatever we can then set a structs "b" to true and then each time check if it's true, if it is then skip it. The problem is that at the end you must run another loop to set them to false again so it won't skip everyone at the next loop. Hopefully Blizzard will let us do stuff like "WAI = WAI[Total]" in the release of SC2.
Well, that's all. If there's anything wrong or if you got some kind of awesome solution to the destruction of structs then feel free to post about it here.
Have a nice day!
Edit: Ohsh-, forgot to say that I think it's best (for now) to do it like it's done in vJASS. Just tons of arrays.
As most of you know you can create structs in Galaxy. Not vJASS structs, but C structs. These structs are like this:
JASS:
struct WAI {
unit u;
fixed x;
fixed y;
fixed z;
};
Those of you who do C programming know you can't make constructors, but you can cheat >
JASS:
int Total = 0;
wai[100] WAI;
struct wai {
unit lol;
int pointer;
bool b;
};
void InitWai(unit lol) {
WAI[Total].lol = lol;
WAI[Total].pointer = Total;
WAI[Total].b = false;
Total+=1;
}
By default all members will have their default values, i.e ints are 0, fixed are 0., units are null, etc.
When you destroy one of them just do like this:
JASS:
wai[100] WAI;
int Total = 0;
struct wai {
unit failzor;
int pointer;
bool b;
};
void Destroy(int which) {
WAI[which].failzor = null;
WAI[which].pointer = Total;
}
Now you're probably wondering "What's the pointer for?". Well, since we can't do "WAI = WAI[Total]" we must then just point to the one at the end of the list. "What about that boolean?", well, to prevent doing stuff to one struct twice or trice or whatever we can then set a structs "b" to true and then each time check if it's true, if it is then skip it. The problem is that at the end you must run another loop to set them to false again so it won't skip everyone at the next loop. Hopefully Blizzard will let us do stuff like "WAI = WAI[Total]" in the release of SC2.
Well, that's all. If there's anything wrong or if you got some kind of awesome solution to the destruction of structs then feel free to post about it here.
Have a nice day!
Edit: Ohsh-, forgot to say that I think it's best (for now) to do it like it's done in vJASS. Just tons of arrays.
Last edited: