Jump to content
Sign in to follow this  
buliwyf

How do i get the custom name of a group?

Recommended Posts

Hi..

I gave a group the name group_s11 in the init row with: group_s11 = group this;

Later i want to get the group name in a script. I tested with player sideChat format["%1", group cursorTarget], but i only get O 1-1-A displayed and not my custom name of the group... :confused:

Any ideas how i can get the custom name?

thx

Share this post


Link to post
Share on other sites

Stop confusing the name of a variable with the name of the variables contents. If you write:

group_s11 = group this;

then you did NOT "name" that group. Instead you've created a global variable called group_s11 which points to that group. Yet, that group still has it's default name/id.

What you probably need is setGroupId.

Share this post


Link to post
Share on other sites

OK... i don`t want to name the group like Squad1... i want to get the variable group_s11 in a script. But i have no idea how to do it. My mission is very dynamic and my script works with a lot of groups. So i need a way to get the variable of the group...

:cool:

Share this post


Link to post
Share on other sites

Well, in case your cursorTarget is a unit, then you get a pointer to that units group with `group cursorTarget`. Isn't that all you need?

Share this post


Link to post
Share on other sites

View my first post... instead of group_s11 i got O1-1-A... that`s the problem.

Share this post


Link to post
Share on other sites
instead of group_s11 i got O1-1-A... that`s the problem.

that's only the string-representation of your group, because you format... ahhh, your pulling off the good old call compile format nonsense, but this time, it's really totally unnecessary! (sorry, I didn't look closer in the first place, hehe)

So instead of:

player sideChat format["%1", group cursorTarget],

try this:

player sideChat (group cursorTarget);

You might also need to first check if cursorTarget returns something useful or your script might easily fall apart...

And please, stop that call compile format nonsense. ;)

Share this post


Link to post
Share on other sites

Groups don't have "names", they have "groups".

It's working how it's intended. group <whatever> doesn't return a string, it returns a group. If you want the player to say "Hey, that's a group soandso!" then you need to use the setGroupID to read whatever you want the player to say.

What exactly are you trying to do with this anyway?

Share this post


Link to post
Share on other sites

Oh, yeah, sure. sideChat expects a string, so that format["%1", (group cursorTarget)] is fine there. You get `O1-1-A`, but you expect to get `group_s11` as a result. Why? What exactly are you testing here?

As explained, group_s11 is not a name, but a variable which holds a pointer to that group. `group cursorTarget` will return exactly the same pointer to that group. And so far, there is no need for your global `group_s11` to exist at all.

Consider:

  _sameGroup = (group cursorTarget) == group_s11;

_sameGroup will be true, if the cursorTarget is indeed part of group_s11 (aslong that global exists and points to that group).

Does this help? :)

Share this post


Link to post
Share on other sites

I have set a variable on the group. I named the group with group_s01=group this; in the leader init.

In a script i wrote group_s01 setVariable ["test",true]; and in another script i want to change the variable with group_s01 setVariable ["test",false];.

But in a dynamic way. my example with cursortarget etc. is only a test to get the variable name of the group.

:butbut:

Share this post


Link to post
Share on other sites
I named the group with group_s01=group this; in the leader init.

No you did not. Instead you've created a new global variable called group_s01 which points to a group.

So instead of:

  group_s01 setVariable ["test",false];

you can write:

  private["_grp"];
  _grp = group cursorTarget;
  _grp setVariable ["test",false];

You create a private variable, get a pointer to the desired group with cursorTarget, do stuff with that group - referenced by _grp.. and then once that script dies, _grp get's thrown away... (while the group itself persists of course and you may always retrieve a pointer to that group again...)

Edited by ruebe

Share this post


Link to post
Share on other sites

I`m so stupid... FPDR

I was completly fixed to the group_s01.. you are so right... :o

Thank you!

Share this post


Link to post
Share on other sites

Yes.. my fault was that i thought group_s01 is the name of the variable. But it is the object the variable is attached to... :o

But thanks for all your help... :dance1:

Share this post


Link to post
Share on other sites

Old thread, but is this possible? I mean getting the actual group name as defined in the editor? I can work around it with setVariable, but is there actually no way to get a string containing the group name?

Share this post


Link to post
Share on other sites

Not unless there is some Reflection API or you attach the name of the variable in a setVariable to the specific group.

Like the others already said, the "name" you give your group in the editor is just a global variable containing a reference to that group.

And since it's a variable, there is no easy way to obtain the lvalue of any object (there was some command to set a vehiclevarname or something like that, maybe that's a try?).

For that to work you need to keep track of every global variable in the current namespace and manage the objects they're referring to (some lookup table).

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  

×