I suck too much to design such trigger...
Basically, I'm trying to spawn random units for random players. Everything is set up, all I'm missing is the player randomization.
I'm trying to randomize between 1 and 3, and then make the editor understand he isn't allowed to pick the same number a second time. Once I have this done, I can copy-paste all my actions in there and Voilą! ;o
None.
So, it picks number 1-3, assigns it to a random player, and then has to pick a new value from the remaining values between 1-3, and assign it to a player that has been assigned no units?
None.
I think the easiest way, at least in theory, to do it would be to set up an array of type boolean of n size, where n is the number of choices you have (in this case, 3 for 1-3), and another array of type boolean of m size, where m is the number of players you have. If it is false, the corresponding value has not been used, if it is true, it has so we must re-select.
The trigger would look like this:
http://vgshorts.com/BBCode/BBCode3.php?ID=16Pick random stuff
Events
Local Variables
Successful Attempts = 0 <Integer>
Choices = false <Boolean[3]>
Players = false <Boolean[3]>
SelectedChoice = 0 <Integer>
SelectedPlayer = 0 <Integer>
Conditions
Actions
General - For each integer Successful Attempts from 1 to 3 with increment 1, do (Actions)
Actions
------- Pick the unit choice
Variable - Set SelectedChoice = (Random integer between 0 and 2)
General - While (Conditions) are true, do (Actions)
Conditions
Choices[SelectedChoice] == true
Actions
Variable - Set SelectedChoice = (Random integer between 0 and 2)
------- Pick the player number
Variable - Set SelectedPlayer = (Random integer between 0 and 2)
General - While (Conditions) are true, do (Actions)
Conditions
Choices[SelectedChoice] == false
Actions
Variable - Set SelectedPlayer = (Random integer between 0 and 2)
------- Actions
------- Do All the unit spawning stuff here ------
Variable - Set Successful Attempts = (Successful Attempts + 1)
Variable - Set Choices[SelectedChoice] = true
Variable - Set Players[SelectedPlayer] = true
It will work, but it does come with the problem that if it keeps randoming the same choice over and over again, it will freeze until it gets a choice that hasn't been selected.
None.
Err, don't add in the
Variable - Set Successful Attempts = (Successful Attempts + 1)
That will break it >.<
Should be like this:
http://vgshorts.com/BBCode/BBCode3.php?ID=17
None.
It could be improved if you kept all possible choices in an array and selected from that instead (would keep it from freezing). Although you would need a function for shrinking the array, not sure which would be fastest.
None.
It could be improved if you kept all possible choices in an array and selected from that instead (would keep it from freezing). Although you would need a function for shrinking the array, not sure which would be fastest.
http://www.staredit.net/starcraft2/Random_integerPlease share your knowledge.
None.
Shrinking an array can generally be about as expensive, and you have to also keep up with the size as well as set up both arrays. Technically, the easiest way to do this would be to use some ADT like a vector/deque/set, even possibly a linked list. But as far as I know SC2 doesn't support these data types.
This was just the first implementation that I came up with that works with the small sets he's looking for.
None.
I wasn't thinking of shrinking the array itself. It would be pretty easy to have a variable to keep track of the length of the array. All you would need to do is move items and reset the length.
Also a linked list is definitely possible because a record is just a struct. Unfortunately you can't pass them to functions so they are really only useful as globals.
EDIT: never mind galaxy is a worse language than I though, you cannot nest structs, and you have to declare something before you use it. There might be a way to do this with pure galaxy but I'm not sure exactly how with this language.
Post has been edited 1 time(s), last time on Aug 29 2010, 12:27 am by Temp.
None.
Well, the problem I see with that is just resizing the array and making sure you never go out of bounds. I don't know if you could make a dynamic resizer in Galaxy that reduces the array size by one and successfully migrates all the data.
None.
You don't need to actually resize the array. You use array that is at least the size of the amount of numbers you want to select from.
None.