• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

OOP-like programming in Galaxy

Status
Not open for further replies.
Level 22
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:

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 >:D

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:
Pointers aren't implemented yet either, but some site claims it will be added. That you can use the operators "&" and "*" like "wai* w = &some wai;"

completely the contrary, before patch 9, there were pointers, but blizzard erased them from all existance, for the shake of being more evil to coders :(.
 
Level 2
Joined
May 15, 2008
Messages
22
So... how does one actually go about using Galaxy script?
That's a good question.

I still have to find out how to write my own custom script functions / structs in Galaxy without relying on stupid GUI (functions don't even work in GUI ~~).
 
Status
Not open for further replies.
Top