I am not entirely familiar with most of the functionality of the editor, but I would like to know if the editor has someway to define sets/memberships of any object (actor, unit, model, behavior, ability, etc.).
The syntax I'm looking for to use is for various triggers:
set Birds = {Eagle, Dove, Raven, ..., Hawk}
set Felines = {Cat, Lion, Leopard, ..., Cheetah}
Trigger Bounty
{
event: a unit dies
if "killed unit" is in Birds:
....give "killing player" 5 minerals
else if "killed unit" is in Felines:
...give "killing player" 15 minerals
}
This is just a bunch of pseudo-code but I saw that you can make arrays as global variables, I just couldn't find a way to test for membership...
You probably want to handle this with a string array. Loop through the array, using StringFind each time, until it returns true, and you have the index of your set. You would also need another array with your mineral information. Once you have the index from the first loop, just use it to retrieve the mineral cost from the second. This is of course made easier if you're using records as Enexy suggested.
User types
Alternatively, you can try using user types. The biggest advantage of which is that it allows you to call back instances with a string identifier (ID)
You can do directly map each of your animals to an instance by ID. When the trigger fires, get the unit type, and use it to call back the instance of your animal, which has a column for it's species, and a column for it's mineral value. Just extract the animal instance and you'll have all the information you need to run the rest of your process. No looping required.
Data + User types
To further beeline the process, you could attach some sort of identifier for your unit data, to flag it as a bird or felines, etc. This way, you can just directly callback the species using categories. Then use the species to find the associated mineral cost from a user type by it's ID.
The advantage of this is that you won't need to have a gazillion records in your user types 'database', just 1 for each species.
Note
Each of these methods have their advantages and disadvantages, with the latter being much faster in terms of process duration, but at the cost of more complexity. In the big picture, the latter are also cleaner solutions, as they make it easier for you to manage your sets. The use of arrays is simple, but it means everytime you add a new unit, you have to go back to your triggers and add the animal in your set. If you forget, you get a free bug. Flagging it in data upon unit creation would yield an immediate effect, no script modification required.
I tried looking at your tutorial for user types but I still haven't found the right way to do what I want (so far the string Array makes the most sense to me, but as you mentioned its not as efficient or fast as user type).
So, I set up a user type that contains two fields: String and Unit (Name and Type).
I have the following set up now:
Event: Any unit dies
Now how do I check if that unit belongs to a user type????
I haven't been able to find a function that returns a boolean like "UnitIsInstanceOfUserType(unit type, unit)"
I actually envisioned it's use in a slightly different way. Rather than checking each set for specific unit types, associate each unit type with a set, and directly call it back. Create the user type ("Sets") to have just 1 field, "Species"
Create your instances to have the ID as the name of the unit "Dog" (instead of an integer as in the tutorial), with the species column "Canine"
When your unit dies, simply user UnitGetType, to retrieve the unit type (Dog) as a string, and use it as your instance.
Then just use UserDataGetString("Sets", "Dog", "Species", 1). Whereby 1 denotes the first value
I haven't been able to find a function that returns a boolean like "UnitIsInstanceOfUserType(unit type, unit)"
I need to look this up when I have access to my editor. If you wish to do it this way, I'm not sure if there's a function that allows it, but I'll help you check (It's not documented in the wiki yet, and I can't find it online).
Edit: I think there might be a function to check if a user type has a specific instance. If so, you could do, UserTypeHasInstance(UserType, Instance), and have it set up how you envisioned it. Just use the unit type as the instance name, and you have a direct mapping
There's no function to check if a user type has an instance, but there is a workaround you can use.
Create your usertype with 1 integer field. This field will act as a boolean flag (0 or 1). Lets call it IsSet.
Set your default instance to have IsSet = 0.
Create new instances with the unit types as your ID, and IsSet = 1
So your user type instances should look something like this:
0, [Default], 0
1, Dog, 1
Your trigger should be something like this
//EventsUnitdies//Varsunitu=EventUnit();stringud="Canines";stringinstance=UnitGetType();intIsSet=UserDataGetInt(ud,instance,"IsSet",1)if(IsSet==1){Displaythemessage"Unit is a user type"}
What we expect to happen here is that, if an instance does not exist within a user type definition, it will return the default instance value, which is 0 (False).
UserDataGetInt("Canine","Tiger","IsSet",1)
Should thus, return 0 (False)
You probably want to create a secondary user type with the titles of all your species and the mineral reward information. Loop through the instances of the secondary user type, to check the sets 1 by one.
If this is not clear, please give me the weekend, I'll script an example map for you.
Hi everyone,
I am not entirely familiar with most of the functionality of the editor, but I would like to know if the editor has someway to define sets/memberships of any object (actor, unit, model, behavior, ability, etc.).
The syntax I'm looking for to use is for various triggers:
set Birds = {Eagle, Dove, Raven, ..., Hawk}
set Felines = {Cat, Lion, Leopard, ..., Cheetah}
Trigger Bounty { event: a unit dies
if "killed unit" is in Birds: ....give "killing player" 5 minerals
else if "killed unit" is in Felines: ...give "killing player" 15 minerals }
This is just a bunch of pseudo-code but I saw that you can make arrays as global variables, I just couldn't find a way to test for membership...
Thanks!
Create a record. Then assign a variable of type record to it. Create your members inside the record itself.
To call it, it should be something like gv_record.object
Arrays/Records
Declare your sets as a string, then use the StringFind(input_string, unit_type) to check your string.
Example:
You probably want to handle this with a string array. Loop through the array, using StringFind each time, until it returns true, and you have the index of your set. You would also need another array with your mineral information. Once you have the index from the first loop, just use it to retrieve the mineral cost from the second. This is of course made easier if you're using records as Enexy suggested.
User types
Alternatively, you can try using user types. The biggest advantage of which is that it allows you to call back instances with a string identifier (ID)
You can do directly map each of your animals to an instance by ID. When the trigger fires, get the unit type, and use it to call back the instance of your animal, which has a column for it's species, and a column for it's mineral value. Just extract the animal instance and you'll have all the information you need to run the rest of your process. No looping required.
Data + User types
To further beeline the process, you could attach some sort of identifier for your unit data, to flag it as a bird or felines, etc. This way, you can just directly callback the species using categories. Then use the species to find the associated mineral cost from a user type by it's ID.
The advantage of this is that you won't need to have a gazillion records in your user types 'database', just 1 for each species.
Note
Each of these methods have their advantages and disadvantages, with the latter being much faster in terms of process duration, but at the cost of more complexity. In the big picture, the latter are also cleaner solutions, as they make it easier for you to manage your sets. The use of arrays is simple, but it means everytime you add a new unit, you have to go back to your triggers and add the animal in your set. If you forget, you get a free bug. Flagging it in data upon unit creation would yield an immediate effect, no script modification required.
I tried looking at your tutorial for user types but I still haven't found the right way to do what I want (so far the string Array makes the most sense to me, but as you mentioned its not as efficient or fast as user type).
So, I set up a user type that contains two fields: String and Unit (Name and Type).
I have the following set up now:
Event: Any unit dies
Now how do I check if that unit belongs to a user type???? I haven't been able to find a function that returns a boolean like "UnitIsInstanceOfUserType(unit type, unit)"
@sethmachine: Go
I actually envisioned it's use in a slightly different way. Rather than checking each set for specific unit types, associate each unit type with a set, and directly call it back. Create the user type ("Sets") to have just 1 field, "Species"
Create your instances to have the ID as the name of the unit "Dog" (instead of an integer as in the tutorial), with the species column "Canine"
When your unit dies, simply user UnitGetType, to retrieve the unit type (Dog) as a string, and use it as your instance.
Then just use UserDataGetString("Sets", "Dog", "Species", 1). Whereby 1 denotes the first value
This should return "Canine"
Note: User type instances are all strings.
I haven't been able to find a function that returns a boolean like "UnitIsInstanceOfUserType(unit type, unit)"
I need to look this up when I have access to my editor. If you wish to do it this way, I'm not sure if there's a function that allows it, but I'll help you check (It's not documented in the wiki yet, and I can't find it online).
Edit: I think there might be a function to check if a user type has a specific instance. If so, you could do, UserTypeHasInstance(UserType, Instance), and have it set up how you envisioned it. Just use the unit type as the instance name, and you have a direct mappingJust checked the new function list: http://us.battle.net/sc2/en/forum/topic/5825622546
There's no function to check if a user type has an instance, but there is a workaround you can use.
Create your usertype with 1 integer field. This field will act as a boolean flag (0 or 1). Lets call it IsSet.
So your user type instances should look something like this:
Your trigger should be something like this
What we expect to happen here is that, if an instance does not exist within a user type definition, it will return the default instance value, which is 0 (False).
Should thus, return 0 (False)
You probably want to create a secondary user type with the titles of all your species and the mineral reward information. Loop through the instances of the secondary user type, to check the sets 1 by one.
If this is not clear, please give me the weekend, I'll script an example map for you.