Dont know much about either, but heres what im looking to do. Would it be possible to set up an array or preset to do these things?
1. Set up a system where one of them basically has a list stored of units I created in the data editor, like Elf1, Elf2, Elf3, Elf4 so that when player 1 - 4 joins a game those elfs would spawn at set points or random points/locations in a map that I set, but also make elf1 be player1 and elf2 be player 2 etc and then also be able to assign like third person control variables to them? For instance, instead of making a crap ton of global variables for w ='s move forward for each players unit, but instead for player 1-4's unit without interfering with each other.
So instead of making 4x well actually 8x Global variables for W Key down and then W key up to move forward and to stop moving forward, I could easily refrence what unit and what key does what with 1 variable for each players unit without spaming my map full of variables.
Players are numbers. so you can simply use arrays like:
Set PlayerUnit[Triggering Player] = Last Created Unit.
or if you create an unit per player:
Set PlayerUnit[1] = Elf(123,123)
The Elf at coördinates 123,123 is used for player 1
then you can use that PlayerUnit variable in other triggers where you have a player.
for example:
Event - Any Player presses W down
Action - Issue order (Halt Position) to PlayerUnit[Triggering Player] (you get the idea XD)
I guess im asking how do you determin an arrays info?
This is how I thought they worked.
Variables that I would have to normaly create for each player using just variables - Just an example
Variable set Unit1 To Playerunits(Array)
Variable set Unit2 to Playerunits(Array) All these being global variables
Variable set Unit3 to Playerunits(Array)
Variable set Unit3 to Playerunits(Array)
Playerunits = Global Variable Array
The way I thought they would work is if I have playermovement keys tied to a specific unit so the player is only controling one unit in my map I could just refer to that global variable array(Playerunits). So anytime I need to refrence something I could just as I said refer to the Array. Same way with movement keys instead of creating W_on, W_on2, W_on3 and W_on4 with each checking for W Key being pressed I could just tie W_on to an array and have the array refer to which player is using the W_on instead of having to create all those global variables for W_on for each individual player.
I guess basicaly what im saying is how I go about having an array know what info to pass on, wether its unit info or grunt info, how do I tie that into into the array?
Why would you want to create an array with all the units a player owns on the map? There are functions to retrieve that information at any time, and they do not require you to maintain the data yourself.
Just to explain arrays though, because you seem to be curious about what they are and how they work, arrays are lists of variables (Technically they are a list of memory locations, but that is outside the scope of the Galaxy Editor). These lists have static sizes, and can be multi-dimensional. Just to give you an idea, lets look at what a 4 length array of Integers would look like with a default value of 5.
(5, 5, 5, 5)
Arrays are `indexed` starting at 0, meaning that the first element in an array is referenced by [0]. That means if we were to run the command:
integerArray[2] = 0;
We would then end up with an array that looks like:
(5, 5, 0, 5)
Now, if you actually wanted to keep track of all the units for each player, you would not want to use arrays of units, you would want a length 4 array of "Unit Group", because Unit Groups can store a dynamic amount of Units and the max size does not need to be defined at instantiation. I hope this helps, but I really am not sure what you are trying to do, so I am not sure it will....
Well what im trying to do is to create a dialog for Player Unit Slection, no matter what Player1 picks he will always be unit one. So for example I have a dialog set where u can choose to play as a Marine or play as a Ghost. On my map I want each player just controling 1 unit, which is a third person shooter with up to 4 players max. This is all fine and dandy the way I have it now having global variables for each player to control his unit as I said above.
uhg, here just let me paste some of my codes so maybe that can clear this up.
Okay so I have this Global variables folder I made and in that folder I created a folder called Third person movement. In this person movement folder I have 4 more folders nmaed
TP1 Movement
TP2 Movement
TP3 Movement
TP4 Movement
Which corisponds to the player right,
So in TP1 Movent I have a crap ton of Global Variables named:
W_On = false <Boolean>
S_On = false <Boolean>
A_On = false <Boolean>
D_On = false <Boolean>
Run_Angle = 0.0 <Real>
Then in TP2 Movement - TP4 Movement I have the same variables just named to relefect the player, so in Player2s Global variables I have
W_On 2 = false <Boolean> and so forth continued on to the 4th player.
So what im trying to do is to find a better way to refer to W_On etc for all players without having to constantly write a ton of variables like I am currently but sitll have it only effect that player so if play one hits W to move forward that command wont be passed on to player 2,3 and 4s units.
If I could find the way to go about doing this, im sure it would be cleaner code and execute a ton faster then having a million variables repeats listed for every player, but not only that but easier to control and refrence for other things.
Now the main reason I started looking into this is because of the Traceline Rrowlands wrote. I was having Syntax error using that and the line refered to Playerunits or some such and rrowland wrote to have it work for multiple players that I would need to write an array linking to the units that each player would control. So here I am lol.. Hopefully this is much clearer.@Honz: Go
Yep, that is much clearer. OK, here is what you want to do. For every 4 variables you have, you want to create one array (You do this by clicking the array checkbox, and increasing the number in the first box to the max length you want, in this case 4), so instead of
Now, when you need to set the variable, you select the array from your variable list, and it will add it as W_on[0], but the "0" will be another value that you can change. You are going to want to change that to the function "Arithmetic (Integer)", with the first value as the player you want to modify the value for (By using "Triggering Player" or "Owner of Unit - Triggering Unit" or whatever) the symbol being minus (-) and the second value being "1". This will make it so that "Player 4" will grab W_on[3] instead of [4], which would result in an error. You would use the same process for accessing the value in the variable.
Yes thank you, this is exactly what I was looking for. Now another question lol... Could you give an example on how I would go about doing that for a individual unit I want each player to receive?
The Unit thing is what really confuses me, because if I do Player_Unit = No Unit<Unit[4]> how do I put Each players unit into that Array?@Honz: Go
This comes down to how you are handling things, and when you need access to the Unit information. If you want to put all of the units into an array like this, you would need to grab all of the units (Hopefully they are all part of a Unit Group), and for each one toss them into the array by using "Owner of Unit". If they are all in a Unit Group, here is how you would do this:
Well the main reason why I want such a thing is for the traceline to properly work and also, because when I issue orders for move forward the way I am doing it now I have to make commands for all 4 players yet again so I link Grunt1 for player, Grunt2 for grunt 2 etc..
The way I have it set up now though, is I created the 4 players units in the game right. So i got 4 units in the game for players 1 through 4. In my code I directly refer to those units I have set up in the game/data Editor and what im trying to do is hopefully do it by array and also not having to just place them in the map. Right now when I start my map I see all 4 units even if its just me playing by myself, which is something id also like to fix, so I could just say and StartLocation1 I want Player 1's chosen unit to spawn etc..@Honz: Go
This way you will only get a unit for each active player, and they will be in your array. You just need to make sure you aren't trying to do actions for "No Game Link" Units in the array :)
So the way im doing it, could be wrong so let me explain how im testing it now
I created my Array which is Player_Units = PresettestUnit <Game Link - Unit[4]> This is type Unit Type
Then I Made a Preset named PresettestUnit Valuetype Custom Script (Game Link) Then for my values I have "Grunt1" "Grunt2" "Grunt3" and "Grunt4"
Does this sound right to you?
I got 4 players, I want each player to get 1 unit and this will be the only unit they will control the entire game, but not only that, it would I think make life easier for me. Such as being able to set constants or whatever to that array or when I issue orders I can pull the orders I want from that array(Issue order UnitArray4 move forward instead of issue order grunt1, issue order grunt2 etc) so Ill have set to an array.
So I make a Global Variable PlaygetsUnit = No Unit <Unit[4]> but from Unit It wont let me pick my hero I want to set to the array, which this is the part that confuses me. I can get it from Unit Type, but then from my personal testing it doesent work for other things such as setting a traceline or whatever and I cant call from picked trigger or whatever.
So if theres anyone that is out there that can list some really good ways to implant arrays, and maybe a few good examples/tutorials, ID apreciate it. This whole thing is starting to give me a headach.
Bump? anyone? Now im using records and my stuff picks the right unit but setting the player_units array to 1, and the record array to 1 still allows more than 1 to spawn....@Sumsin: Go
Dont know much about either, but heres what im looking to do. Would it be possible to set up an array or preset to do these things?
1. Set up a system where one of them basically has a list stored of units I created in the data editor, like Elf1, Elf2, Elf3, Elf4 so that when player 1 - 4 joins a game those elfs would spawn at set points or random points/locations in a map that I set, but also make elf1 be player1 and elf2 be player 2 etc and then also be able to assign like third person control variables to them? For instance, instead of making a crap ton of global variables for w ='s move forward for each players unit, but instead for player 1-4's unit without interfering with each other.
So instead of making 4x well actually 8x Global variables for W Key down and then W key up to move forward and to stop moving forward, I could easily refrence what unit and what key does what with 1 variable for each players unit without spaming my map full of variables.
Any help would be apreciated.
@Sumsin: Go
Players are numbers. so you can simply use arrays like:
Set PlayerUnit[Triggering Player] = Last Created Unit.
or if you create an unit per player:
Set PlayerUnit[1] = Elf(123,123)
The Elf at coördinates 123,123 is used for player 1
then you can use that PlayerUnit variable in other triggers where you have a player.
for example:
Event - Any Player presses W down
Action - Issue order (Halt Position) to PlayerUnit[Triggering Player] (you get the idea XD)
Still kind of confused, but thanks for the reply.
I guess im asking how do you determin an arrays info?
This is how I thought they worked.
Variables that I would have to normaly create for each player using just variables - Just an example
Variable set Unit1 To Playerunits(Array) Variable set Unit2 to Playerunits(Array) All these being global variables Variable set Unit3 to Playerunits(Array) Variable set Unit3 to Playerunits(Array)
Playerunits = Global Variable Array
The way I thought they would work is if I have playermovement keys tied to a specific unit so the player is only controling one unit in my map I could just refer to that global variable array(Playerunits). So anytime I need to refrence something I could just as I said refer to the Array. Same way with movement keys instead of creating W_on, W_on2, W_on3 and W_on4 with each checking for W Key being pressed I could just tie W_on to an array and have the array refer to which player is using the W_on instead of having to create all those global variables for W_on for each individual player.
I guess basicaly what im saying is how I go about having an array know what info to pass on, wether its unit info or grunt info, how do I tie that into into the array?
Any further assistance would be apreciated
Say I wanted Playerunits to be basically all my players 1-4 units they will control in the map.
@Sumsin: Go
Why would you want to create an array with all the units a player owns on the map? There are functions to retrieve that information at any time, and they do not require you to maintain the data yourself.
Just to explain arrays though, because you seem to be curious about what they are and how they work, arrays are lists of variables (Technically they are a list of memory locations, but that is outside the scope of the Galaxy Editor). These lists have static sizes, and can be multi-dimensional. Just to give you an idea, lets look at what a 4 length array of Integers would look like with a default value of 5.
(5, 5, 5, 5)
Arrays are `indexed` starting at 0, meaning that the first element in an array is referenced by [0]. That means if we were to run the command:
integerArray[2] = 0;
We would then end up with an array that looks like:
(5, 5, 0, 5)
Now, if you actually wanted to keep track of all the units for each player, you would not want to use arrays of units, you would want a length 4 array of "Unit Group", because Unit Groups can store a dynamic amount of Units and the max size does not need to be defined at instantiation. I hope this helps, but I really am not sure what you are trying to do, so I am not sure it will....
Well what im trying to do is to create a dialog for Player Unit Slection, no matter what Player1 picks he will always be unit one. So for example I have a dialog set where u can choose to play as a Marine or play as a Ghost. On my map I want each player just controling 1 unit, which is a third person shooter with up to 4 players max. This is all fine and dandy the way I have it now having global variables for each player to control his unit as I said above.
uhg, here just let me paste some of my codes so maybe that can clear this up.
Okay so I have this Global variables folder I made and in that folder I created a folder called Third person movement. In this person movement folder I have 4 more folders nmaed TP1 Movement TP2 Movement TP3 Movement TP4 Movement Which corisponds to the player right,
So in TP1 Movent I have a crap ton of Global Variables named: W_On = false <Boolean> S_On = false <Boolean> A_On = false <Boolean> D_On = false <Boolean> Run_Angle = 0.0 <Real>
Then in TP2 Movement - TP4 Movement I have the same variables just named to relefect the player, so in Player2s Global variables I have W_On 2 = false <Boolean> and so forth continued on to the 4th player.
So what im trying to do is to find a better way to refer to W_On etc for all players without having to constantly write a ton of variables like I am currently but sitll have it only effect that player so if play one hits W to move forward that command wont be passed on to player 2,3 and 4s units.
If I could find the way to go about doing this, im sure it would be cleaner code and execute a ton faster then having a million variables repeats listed for every player, but not only that but easier to control and refrence for other things.
Now the main reason I started looking into this is because of the Traceline Rrowlands wrote. I was having Syntax error using that and the line refered to Playerunits or some such and rrowland wrote to have it work for multiple players that I would need to write an array linking to the units that each player would control. So here I am lol.. Hopefully this is much clearer.@Honz: Go
Bump, anyone?
@Sumsin: Go
Yep, that is much clearer. OK, here is what you want to do. For every 4 variables you have, you want to create one array (You do this by clicking the array checkbox, and increasing the number in the first box to the max length you want, in this case 4), so instead of
W_on = false<Boolean>
W_on2 = false<Boolean>
W_on3 = false<Boolean>
W_on4 = false<Boolean>
you have
W_on = false <Boolean[4]>
Now, when you need to set the variable, you select the array from your variable list, and it will add it as W_on[0], but the "0" will be another value that you can change. You are going to want to change that to the function "Arithmetic (Integer)", with the first value as the player you want to modify the value for (By using "Triggering Player" or "Owner of Unit - Triggering Unit" or whatever) the symbol being minus (-) and the second value being "1". This will make it so that "Player 4" will grab W_on[3] instead of [4], which would result in an error. You would use the same process for accessing the value in the variable.
Yes thank you, this is exactly what I was looking for. Now another question lol... Could you give an example on how I would go about doing that for a individual unit I want each player to receive?
The Unit thing is what really confuses me, because if I do Player_Unit = No Unit<Unit[4]> how do I put Each players unit into that Array?@Honz: Go
@Sumsin: Go
This comes down to how you are handling things, and when you need access to the Unit information. If you want to put all of the units into an array like this, you would need to grab all of the units (Hopefully they are all part of a Unit Group), and for each one toss them into the array by using "Owner of Unit". If they are all in a Unit Group, here is how you would do this:
Well the main reason why I want such a thing is for the traceline to properly work and also, because when I issue orders for move forward the way I am doing it now I have to make commands for all 4 players yet again so I link Grunt1 for player, Grunt2 for grunt 2 etc..
The way I have it set up now though, is I created the 4 players units in the game right. So i got 4 units in the game for players 1 through 4. In my code I directly refer to those units I have set up in the game/data Editor and what im trying to do is hopefully do it by array and also not having to just place them in the map. Right now when I start my map I see all 4 units even if its just me playing by myself, which is something id also like to fix, so I could just say and StartLocation1 I want Player 1's chosen unit to spawn etc..@Honz: Go
@Sumsin: Go
In your initialization trigger do something like this:
This way you will only get a unit for each active player, and they will be in your array. You just need to make sure you aren't trying to do actions for "No Game Link" Units in the array :)
Alright thanks, ill give this a shot real quick and see how it turns out. ill post back with my results.@Honz: Go
So the way im doing it, could be wrong so let me explain how im testing it now I created my Array which is Player_Units = PresettestUnit <Game Link - Unit[4]> This is type Unit Type Then I Made a Preset named PresettestUnit Valuetype Custom Script (Game Link) Then for my values I have "Grunt1" "Grunt2" "Grunt3" and "Grunt4" Does this sound right to you?
Well still cant figure out how to tie units to an array... anyone?
To be clear, cause I still cant get this... lol
I got 4 players, I want each player to get 1 unit and this will be the only unit they will control the entire game, but not only that, it would I think make life easier for me. Such as being able to set constants or whatever to that array or when I issue orders I can pull the orders I want from that array(Issue order UnitArray4 move forward instead of issue order grunt1, issue order grunt2 etc) so Ill have set to an array.
So I make a Global Variable PlaygetsUnit = No Unit <Unit[4]> but from Unit It wont let me pick my hero I want to set to the array, which this is the part that confuses me. I can get it from Unit Type, but then from my personal testing it doesent work for other things such as setting a traceline or whatever and I cant call from picked trigger or whatever.
So if theres anyone that is out there that can list some really good ways to implant arrays, and maybe a few good examples/tutorials, ID apreciate it. This whole thing is starting to give me a headach.
Bump? anyone? Now im using records and my stuff picks the right unit but setting the player_units array to 1, and the record array to 1 still allows more than 1 to spawn....@Sumsin: Go
bumpppp
Screen shots of what im doing... someone please help lol.
Bump