Hi guys, I've been browsing the forums for some time now but this is the first time i post. I'm working on a map right now that features custom buff system(as opposed to the one used by blizzard.) and what i'm struggling with is storing up all my info in a good place. Right now what i'm doing is using alot of custom values assigned to the unit to know which buffs are active, but it look really ugly so i wanna try something different. I'm a little pessimistic about this but I have to ask because I really wish it was possible - can you create new classes and instantiate them in galaxy like you can in other object oriented languages? If not, are data tables the next very best thing? I have no experience with any data manipulation so I'm little hesitant, but from what I'm seeing you could use data tables somewhat like I wanna use classes(except methods ofc) - create a Data table variable and store alot of different data types within it, and later recall it by name. Can any1 confirm or guide me to the best way to do this?
The closest thing to classes in Galaxy are the Structs (or Records in Gui). They are instanciated, can hold a variety of variables, but no methods or static members. So basically, they are just a way to group up arrays. Still, you can probably use them for your desired application, store one instance in each unit's custom script and store the buffs in the struct.
Data tables are an option as well, certain language extensions used it to simulate functional classes or several other things. However, data table's access times (especcially writing) are significantly longer than variables/structs, something to keep in mind.
You can define structs, as stated above. However, you can't have functions that return structs, therefore you can't dynamically create new instances of structs. You can declare a struct locally, but since you can't return it, this more or less means it only lasts the duration of that function. Therefore, any structs you want to use in more than one trigger need to be declared globally.
Structs can't be saved in the Data Table. You could, however, declare in advance a large array of your struct, and make use of them as necessary by passing around integer indexes into this array. Depending on what you plan to use this for, this can be quite expensive.
You can pass structs to functions using structref. Example:
structthing{...};typedefstructref<thing>thing_r;voidinitThing(thing_rt){//do stuff to t}
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hi guys, I've been browsing the forums for some time now but this is the first time i post. I'm working on a map right now that features custom buff system(as opposed to the one used by blizzard.) and what i'm struggling with is storing up all my info in a good place. Right now what i'm doing is using alot of custom values assigned to the unit to know which buffs are active, but it look really ugly so i wanna try something different. I'm a little pessimistic about this but I have to ask because I really wish it was possible - can you create new classes and instantiate them in galaxy like you can in other object oriented languages? If not, are data tables the next very best thing? I have no experience with any data manipulation so I'm little hesitant, but from what I'm seeing you could use data tables somewhat like I wanna use classes(except methods ofc) - create a Data table variable and store alot of different data types within it, and later recall it by name. Can any1 confirm or guide me to the best way to do this?
The closest thing to classes in Galaxy are the Structs (or Records in Gui). They are instanciated, can hold a variety of variables, but no methods or static members. So basically, they are just a way to group up arrays. Still, you can probably use them for your desired application, store one instance in each unit's custom script and store the buffs in the struct.
Data tables are an option as well, certain language extensions used it to simulate functional classes or several other things. However, data table's access times (especcially writing) are significantly longer than variables/structs, something to keep in mind.
Seems like a worthy topic.. I would like to see this actually in action I look forward to it.
@DimitarK: Go
Kueken is mostly correct. However, structs are entirely capable of holding methods - using the funcref type.
Example:
To give you some additional information:
You can define structs, as stated above. However, you can't have functions that return structs, therefore you can't dynamically create new instances of structs. You can declare a struct locally, but since you can't return it, this more or less means it only lasts the duration of that function. Therefore, any structs you want to use in more than one trigger need to be declared globally.
Structs can't be saved in the Data Table. You could, however, declare in advance a large array of your struct, and make use of them as necessary by passing around integer indexes into this array. Depending on what you plan to use this for, this can be quite expensive.
You can pass structs to functions using structref. Example: