I am working with a custom UI and a lot of settings that won't be in the galaxy editor. I'm not sure if there is a built in function like a database to be able to store attributes for a given ID. For example, I want to reference a unit type and given attributes about it. Currently I can create an array indexed by unit type but I can only store one variable at a time. This leads me to have to replicate the arrays for each type of variable I want to store, then cross reference them in a complicated fashion. What this system comes down to is a relational database with each table being two columns with many rows, the first column being the ID and the second column being the attribute.
Basically, I want to be able to create a database within the galaxy editor. This data is not user specific, nor will it be modified.
You could make a Record with all the variables you want to save for each unit type. Then make an array index by unit type with that Record. That would allow you to save all the data you want for each unit type in one variable.
However, i find Records to be a bit hard to use in that you can only set or copy single values at a time, you cant pass it to a function and i cant seem to directly reference a value from a Record in a condition (have to use a temp variable for that).
So I have an array of records. Currently the records contain int, text, image. I have a record for each unit type. I want to reference these, let's say image when I create a dialog image. So it would be like:
Create dialog image for dialog with dimensions x, y anchored to bottom left, with offset x, y setting the tooltip to "Text" using the image Record[?].Image, etc. etc.
My question is the "?" part. I want to be able to pick which record, and thus which image, based on Unit Type. I could create a massive switch function to return the array position based on the Unit Type with something like:
Switch based on Unit Type
Case(Probe)
Return 0
Case(Zealot)
Return 1
This is possible but seams like a lot of code and therefore I am looking to see if there is another way to do this.
You are interested in data tables. Since unit types in SC2 are basically strings, you could easily use data tables to store whatever you want.
Data tables can store any value under a string. If you make a function that prefixes the unit type and then the key, you can quite easily create extra values.
In GUI they are relatively simple and all the "Save functions" are under the data tables tab of the actions. From there you simply select the type of data you wish to save (if you wished to save a real value, select the save real value one). The function will prompt you for the value to save and a string which is the key that the value is saved under.
If you're going to be saving a lot of data under unit type, the first thing you should do is make a FormatUnitTypeData function. Its parameters should be a unit type and a string value, and its return should be a custom script that reads like this:
return lp_unitType+"_"+lp_key;
Where unitType is the variable for the unit type, and key is the variable for the string key.
Then you can save unit data quite easily. If you wanted to save a real value for a unit type, you'd find the Save Data Table Value (Real) action, fill in the real value you wish to save, then for the Name section find your FormatUnitTypeData function. It should be straightforward from there.
To load this data at any time, simply find the Value from Data Table (real) function when using set variable, and use the same unit type and key formatted by your FormatUnitTypeData function for the name section.
I am working with a custom UI and a lot of settings that won't be in the galaxy editor. I'm not sure if there is a built in function like a database to be able to store attributes for a given ID. For example, I want to reference a unit type and given attributes about it. Currently I can create an array indexed by unit type but I can only store one variable at a time. This leads me to have to replicate the arrays for each type of variable I want to store, then cross reference them in a complicated fashion. What this system comes down to is a relational database with each table being two columns with many rows, the first column being the ID and the second column being the attribute.
Basically, I want to be able to create a database within the galaxy editor. This data is not user specific, nor will it be modified.
Example:
Unit_Type String_Var Int_Var
Immortal Text 5,000
You could make a Record with all the variables you want to save for each unit type. Then make an array index by unit type with that Record. That would allow you to save all the data you want for each unit type in one variable.
However, i find Records to be a bit hard to use in that you can only set or copy single values at a time, you cant pass it to a function and i cant seem to directly reference a value from a Record in a condition (have to use a temp variable for that).
So I have an array of records. Currently the records contain int, text, image. I have a record for each unit type. I want to reference these, let's say image when I create a dialog image. So it would be like:
Create dialog image for dialog with dimensions x, y anchored to bottom left, with offset x, y setting the tooltip to "Text" using the image Record[?].Image, etc. etc.
My question is the "?" part. I want to be able to pick which record, and thus which image, based on Unit Type. I could create a massive switch function to return the array position based on the Unit Type with something like:
Switch based on Unit Type Case(Probe) Return 0 Case(Zealot) Return 1
This is possible but seams like a lot of code and therefore I am looking to see if there is another way to do this.
You are interested in data tables. Since unit types in SC2 are basically strings, you could easily use data tables to store whatever you want.
Data tables can store any value under a string. If you make a function that prefixes the unit type and then the key, you can quite easily create extra values.
I haven't found how to use data tables, where would I begin?
In GUI they are relatively simple and all the "Save functions" are under the data tables tab of the actions. From there you simply select the type of data you wish to save (if you wished to save a real value, select the save real value one). The function will prompt you for the value to save and a string which is the key that the value is saved under. If you're going to be saving a lot of data under unit type, the first thing you should do is make a FormatUnitTypeData function. Its parameters should be a unit type and a string value, and its return should be a custom script that reads like this:
return lp_unitType+"_"+lp_key;
Where unitType is the variable for the unit type, and key is the variable for the string key. Then you can save unit data quite easily. If you wanted to save a real value for a unit type, you'd find the Save Data Table Value (Real) action, fill in the real value you wish to save, then for the Name section find your FormatUnitTypeData function. It should be straightforward from there. To load this data at any time, simply find the Value from Data Table (real) function when using set variable, and use the same unit type and key formatted by your FormatUnitTypeData function for the name section.