From what I understand the best way to collect items is in a record, but it seems impossible to return a record. If this is possible and I just haven't realized how please let me know.
I have two workarounds so far, both of which are pretty hackish. Units can store unlimted reals in their custom values, and can be returned. Strings can be parsed, so you can encode your values in them. Neither of these are intuitive in the least, though.
A string composite would probably be the easiest thing to use. Why would you want a single function to return multiple values though? You would have to separate it anyway to make use of it. It seems like you might as well use multiple functions for each variable you're trying to return.
Why would you ever want to return an object in java? Objects potentially have more than 1 piece of information in them, why would you want to return something with multiple values?
I have a record called Item that stores information about how I want it to work. In order to easily pick random items appropriately for certain conditions, I have each item categorized by class, which is just an integer array. In order to conveniently store all of my items of a class, they're also an array. Its not a 2 dimensional array exactly, but you can think of it like that.
Now, in order to access a specific item in a 2 dimensional array, you need both dimensions. If I could return a record, I could just copy the Item outright, but I can't, so I need to return both values.
if i remember correctly galaxy can take struct as parameters so maybe it can return them too
Unfortunately now. In Sc2 it's impossible to return a record.
There are two ways:
1) Use Global Variables. Your function sets these variables to some value, and the caller can then read the variables and use them.
2) Same as above, but instead of Global Variables you use one Global Record in which you store all variables.
Units can store unlimted reals in their custom values.
I think there are 64 custom values per unit (didn't test myself). But you can add many information onto a single unit, if you give the unit an inventory and items which can hold 64 more variables.
Also, I have no idea why someone should use records ever... just use global variables.
Another solution would be that you change the design of your system.
What you could do is to make as many return-type functions as you need to describe your item and one, which calls all of them (you might also want to add an additional integer parameter to call your arrays in every of the return-type functions) . This way it might work out, depending on what you are trying to achieve. I only had need once for such a combination yet, but I know what you mean - I'd also like a function which can return multiple values.
What you could do is to make as many return-type functions as you need to describe your item and one, which calls all of them (you might also want to add an additional integer parameter to call your arrays in every of the return-type functions) . This way it might work out, depending on what you are trying to achieve. I only had need once for such a combination yet, but I know what you mean - I'd also like a function which can return multiple values.
When you think about function returning multiple thing how exactly you see this? It would be only possible and reasonable with structs, otherwise it would require whole scripting engine overhaul.
1) Use Global Variables. Your function sets these variables to some value, and the caller can then read the variables and use them. 2) Same as above, but instead of Global Variables you use one Global Record in which you store all variables.
How costly are locks going to be if I expect somewhere around a maximum of 3-4 threads trying to use it at the same time? Because locks are the only way global anythings are going to work.
Also, I have no idea why someone should use records ever... just use global variables.
On my last project I never used records, just globals. It got pretty messy.
If you ever have a number of arrays sharing the same size (usually when its one for each player or something) turning them into records instead is a great way to reduce clutter. I hate having more than a full screen when using the Set Variable function.
Since I just need two integers, is it possible to pass back an integer array? If so, how do I handle it on the receiving end? Do I need an array of the exact same size to avoid overflows?
When you think about function returning multiple thing how exactly you see this? It would be only possible and reasonable with structs, otherwise it would require whole scripting engine overhaul.
From what I understand the best way to collect items is in a record, but it seems impossible to return a record. If this is possible and I just haven't realized how please let me know.
I have two workarounds so far, both of which are pretty hackish. Units can store unlimted reals in their custom values, and can be returned. Strings can be parsed, so you can encode your values in them. Neither of these are intuitive in the least, though.
Is there anything that will just feel 'right'?
@A52BcE: Go
A string composite would probably be the easiest thing to use. Why would you want a single function to return multiple values though? You would have to separate it anyway to make use of it. It seems like you might as well use multiple functions for each variable you're trying to return.
@BasharTeg: Go
Why would you ever want to return an object in java? Objects potentially have more than 1 piece of information in them, why would you want to return something with multiple values?
I have a record called Item that stores information about how I want it to work. In order to easily pick random items appropriately for certain conditions, I have each item categorized by class, which is just an integer array. In order to conveniently store all of my items of a class, they're also an array. Its not a 2 dimensional array exactly, but you can think of it like that.
Now, in order to access a specific item in a 2 dimensional array, you need both dimensions. If I could return a record, I could just copy the Item outright, but I can't, so I need to return both values.
if i remember correctly galaxy
++
can take struct as parameters so maybe it can return them tooUnfortunately now. In Sc2 it's impossible to return a record.
There are two ways:
1) Use Global Variables. Your function sets these variables to some value, and the caller can then read the variables and use them. 2) Same as above, but instead of Global Variables you use one Global Record in which you store all variables.
I think there are 64 custom values per unit (didn't test myself). But you can add many information onto a single unit, if you give the unit an inventory and items which can hold 64 more variables.
Also, I have no idea why someone should use records ever... just use global variables.
Another solution would be that you change the design of your system.
@A52BcE: Go
What you could do is to make as many return-type functions as you need to describe your item and one, which calls all of them (you might also want to add an additional integer parameter to call your arrays in every of the return-type functions) . This way it might work out, depending on what you are trying to achieve. I only had need once for such a combination yet, but I know what you mean - I'd also like a function which can return multiple values.
There's a lot of reasons to use records. A lot....
When you think about function returning multiple thing how exactly you see this? It would be only possible and reasonable with structs, otherwise it would require whole scripting engine overhaul.
How costly are locks going to be if I expect somewhere around a maximum of 3-4 threads trying to use it at the same time? Because locks are the only way global anythings are going to work.
On my last project I never used records, just globals. It got pretty messy. If you ever have a number of arrays sharing the same size (usually when its one for each player or something) turning them into records instead is a great way to reduce clutter. I hate having more than a full screen when using the Set Variable function.
Since I just need two integers, is it possible to pass back an integer array? If so, how do I handle it on the receiving end? Do I need an array of the exact same size to avoid overflows?
@Nerfpl: Go