Jump to content
Sign in to follow this  
whiztler

Get the variable of a group

Recommended Posts

Let's say in the unit (leader) init you have

myGroup = group this; myGroup setGroupID ["SuperGroup"];

Since 'myGroup' is a global variable I should be able to query it in a hint.

hint str group player

returns B SuperGroup

How do I get the group identifier (myGroup)?

Share this post


Link to post
Share on other sites

hint str groupID (group Player)

Returns SuperGroup

I need it to return ​myGroup

Share this post


Link to post
Share on other sites

Do you have any more intel of what you're trying to achieve? To identify whether a group is myGroup you could also do:

(group player) == myGroup

Share this post


Link to post
Share on other sites
Do you have any more intel of what you're trying to achieve? To identify whether a group is myGroup you could also do:

(group player) == myGroup

But that only works if the group identifier (myGroup) is known. I realize you can apply commands to a group without knowing the group identifier. I find it strange though that one cannot display the group identifier in a hint for instance.

Share this post


Link to post
Share on other sites

That is because you're trying to display the variable name. What the game does (and what's logical) is displaying the variable value or referenced item, in this case the group name which is "B Bla123". Still, more details about what you're trying to achieve would be helpful. There's also the allGroups command which gives you an array of all groups.

Share this post


Link to post
Share on other sites
That is because you're trying to display the variable name. What the game does (and what's logical) is displaying the variable value or referenced item, in this case the group name which is "B Bla123". Still, more details about what you're trying to achieve would be helpful. There's also the allGroups command which gives you an array of all groups.

It actually isn't the vehicle name. It's the identifier of the variable. allGroups does not return the identifier.

Re usage, let's just stay with that I need to display it in a hint. Don't want to sound like a pain or anything but there must be a way to get the identifier?

Share this post


Link to post
Share on other sites

Looks like you want setVehicleVarName/vehicleVarName for groups... well it doesn't exist.

Share this post


Link to post
Share on other sites

Wait, this is weird. Are you really asking how to get the variable name from in-game?

---------- Post added at 02:48 ---------- Previous post was at 02:23 ----------

I think this is going to be as good as it gets:

_vars = allVariables missionNamespace;
_var = "";
{
if ((call compile _x) == myGroup) then
{
	_var = _x;
};
} forEach _vars;

Share this post


Link to post
Share on other sites

Re usage, let's just stay with that I need to display it in a hint. Don't want to sound like a pain or anything but there must be a way to get the identifier?

I needed to do something like this once. I ended up assigning a variable to each of the groups I needed to check that was the same as their group name.

myGroup setVariable ["V_group", "myGroup"];

//--- in some script
_grp = _this;
_grp getVariable "V_group";   
hint str _grp;

the hint returns "myGroup". Kind of hacky and might not be feasible depending on the scope of what you're doing.

Share this post


Link to post
Share on other sites
Wait, this is weird. Are you really asking how to get the variable name from in-game?

---------- Post added at 02:48 ---------- Previous post was at 02:23 ----------

I think this is going to be as good as it gets:

_vars = allVariables missionNamespace;
_var = "";
{
if ((call compile _x) == myGroup) then
{
	_var = _x;
};
} forEach _vars;

Almost.

[color="#FF8040"]KK_fnc_objectVarNames [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
[color="#191970"][b]private[/b][/color] [color="#7A7A7A"]"_names"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_names[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]{[/b][/color]
	[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]missionNamespace[/b][/color] [color="#191970"][b]getVariable[/b][/color] [color="#000000"]_x[/color] [color="#191970"][b]isEqualTo[/b][/color] [color="#000000"]_this[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
		[color="#1874CD"]_names[/color] [color="#191970"][b]pushBack[/b][/color] [color="#000000"]_x[/color][color="#8B3E2F"][b];[/b][/color]
	[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]forEach[/b][/color] [color="#191970"][b]allVariables[/b][/color] [color="#191970"][b]missionNamespace[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_names[/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#006400"][i]//example[/i][/color]
myGroup [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]group[/b][/color] [color="#000000"]player[/color][color="#8B3E2F"][b];[/b][/color]
aGroup [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]group[/b][/color] [color="#000000"]player[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]hint[/b][/color] [color="#191970"][b]str[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]group[/b][/color] [color="#000000"]player[/color] [color="#191970"][b]call[/b][/color] KK_fnc_objectVarNames[color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]//["agroup","mygroup"][/i][/color][/color]

Made with KK's SQF to BBCode Converter

The reason is that there could be more variables referencing the same object, and you do not really want to call compile a variable you know nothing about.

Edited by Killzone_Kid

Share this post


Link to post
Share on other sites

Thanks, KK. Thread is kind of weird. I'm convinced OP has a misunderstanding of what exactly a variable is at the "fundamentals"-level

Share this post


Link to post
Share on other sites
Thanks, KK. Thread is kind of weird. I'm convinced OP has a misunderstanding of what exactly a variable is at the "fundamentals"-level

I assure you that is not the case.Just like most fooks in this thread I like to learn more about the inner workings of SQF. I came across this 'problem' when I wanted the server to apply custom groupID's. I realize there are other ways to do it, but other ways are not alway the most efficient way. And for Multiplayer I thrive for the most efficient way to get things done.KK hit the nail on its head in his first reply.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×