Jump to content
stuguy

passing parameters getting returns problem

Recommended Posts

I am very familiar with programming and I have been experimenting how ARMA passes variables to functions.  I think I understand how params and param work, but I am having difficulty calling a function to return a desired result.  This below code is simply trying to call on a function that requires the input of a group, in this instance, I am sending it "group player" with the call function.  From what I understand, the function returns the last line, so the count should return the number of men in the group.  However, it sends an error stating that it is expecting a number, but is getting type string.  This is confusing because I am sending it Group Player, an array of men to be counted.  Just writing a count out with "_num = count units group player" works without a hitch.  So why is it I am unable to pass it the _grp parameter?

 

getGrpCount = {
    param ["_grp"];
    count units _grp;
};
_num = [group player] call getGrpCount;
hint format ["%1",_num];

no workie

 

_num = count units group player;
hint format ["%1",_num];

works
Existing user? Sign In

Share this post


Link to post
Share on other sites

I figured it out.  It was passing an array when the code is expecting an object type.  I simply erased the [] before call and used _this.  Though, I am still confused why param ["_grp"] doesn't seem to want to work even with the array fix.

getGrpCount = {
    count units _this;
};
_num = group player call getGrpCount;
hint format ["%1",_num];

 

Share this post


Link to post
Share on other sites
5 hours ago, killzone_kid said:

https://community.bistudio.com/wiki/param there is your answer, follow the syntax

I RTFM.  The way I understood it was that param "extracts a single value with given index from input argument".  I had thought I was passing in a single variable and thus only needed to use param.

Share this post


Link to post
Share on other sites

The syntax is clear, you need to pass index with param minimum. Index is NUMBER you were pasing STRING. I don't see how this could be misinterpreted in any way.

Share this post


Link to post
Share on other sites

that makes much more since.  I didn't even realize that error.  Come to think of it, the debuger mentioned something about string.  Thank you for the clarification.  Keep in mind, I only started getting back into arma scripting only yesterday, so I don't see as clearly as you do. 

Share this post


Link to post
Share on other sites
18 minutes ago, stuguy said:

that makes much more since.  I didn't even realize that error.  Come to think of it, the debuger mentioned something about string.  Thank you for the clarification.  Keep in mind, I only started getting back into arma scripting only yesterday, so I don't see as clearly as you do. 


In this case, always run Arma with -showScriptErrors and pay extra attention to data types you are passing to the commands. You can check datatype with 
 

hint typeName _yourvariable

 

Share this post


Link to post
Share on other sites
2 hours ago, killzone_kid said:


In this case, always run Arma with -showScriptErrors and pay extra attention to data types you are passing to the commands. You can check datatype with 
 


hint typeName _yourvariable

 

oh man.  that's a big help.  I was relying solely on the mission editor command exec utility, and the errors are teeny weeny and not always easy to read.  I started using hints more as I tested my functions, I will be sure to use typeName, good call.  Thanks for the advice.

Share this post


Link to post
Share on other sites

The errors are also printed to log file in User\AppData\Local\Arma 3 with extension .rpt.  It's good for errors appearing in quick succession since only one message is displayed at a time. 

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

×