Jump to content
razzored

Help with creating a array.

Recommended Posts

How would one go about making a script that defines a bunch of objects as object namespace..
Example if i then later call a ["coolstuff", true] call SomeFunction.
How do i make it so that the script knows that "coolstuff" is EVERY ect sandbag and concretewall placed in the mission.. just two objects used as examples. 

Thanks in advance, any help appriciated 🙂

Share this post


Link to post
Share on other sites

@pierremgi Thanks for the reply, sadly that would not work as i only want certain objects, ect all Sandbags and all tank traps.. but not tents, this is again just an example.
But due to the specificness, i wanna be able to just use a script to classify all the object names into one array and call using a variable.

Share this post


Link to post
Share on other sites

I'm sure that what you are asking for is possible, I'm just not sure I understand what you are asking...

In your example, what is "coolstuff"?

  • Is it a classname which you use to retrieve all objects with that class?
  • Is it a variable name that refers to a (pre-made) array of objects?
  • Or is it a string parameter that is used inside SomeFunction to run specific functionality?

Share this post


Link to post
Share on other sites

@Sgt. Dennenboom a variable i want applied to all objects of a class, including those spawned AFTER mission start.
Example The variable would be "IsSandbag" would be applied to all of the sandbags.
Afterwhich i will be able to run a secondary script that recognizes them by 
["issandbag", true] call Cool_Api_addobjectVariable;

So i need something that will do checks for whenever new sandbags gets spawned or made and then applies "issandbag".
Just like vehicles can have "IsLocked" or players in ace "IsMedic".
But since sandbag is an example and it is regarding more than 1 object type, it would need to check for example - If ["land_sandbag_F", "Concretewall_long", "other_classname"] setvariable Issandbag

Share this post


Link to post
Share on other sites

Sorry that my explanation or well, lack thereof is so retarded. I feel like a catholic priest trying to explain quantum mechanics.

Share this post


Link to post
Share on other sites
_checkTime = 30; //check all 30 seconds for new objects

allNeededObjectsAreSpawned = false;  // set this to true to stop searching for 
private _classNames = ["land_sandbag_F", "Concretewall_long", "other_classname"] apply {toLower _x};

while {!allNeededObjectsAreSpawned} do
{
 private _newObjects = allMissionObjects select 
 { 
  private _objClass = toLower (typeOf _x);
  private _obj =_x;
  (_classNames findIf { _x isEqualTo _objClass } > -1) &&
  isNil {_obj getVariable "coolStuffVariableAsIWantItToHaveOnCoolObjects"}
 };

 _d = {_x setVariable ["coolStuffVariableAsIWantItToHaveOnCoolObjects", myWantedCoolValue, true]} count _newObjects;

 sleep _checkTime;
};

not tested but should set that variable to all new spawned objects

  • Like 2

Share this post


Link to post
Share on other sites

Hot damn, Thank you so much @sarogahtyp You are a real life saver, i will test it asap, as for the VALUE in example "mywantedcoolvalue" its not something i would wanna think too much over right? I've read up on it, but it really seems pointless, other than having to exist, well atleast in this scenario, i can imagine some scripts and systems where its good to be able to call values using the variable, but here its just there as a technicality? right?

Also, the reason for not setting their variable using a spawn script, is because many of the objects will be made in the mission by players ect and multiple other factors where its easier to just have a script keep track of it.
 

Share this post


Link to post
Share on other sites

 

 

myWantedCoolValue is a placeholder for whatever value u want those variable to have on init

Share this post


Link to post
Share on other sites

Or perhaps, you should describe what you intend to do/obtain. Applying a variable on something spawned is perhaps not useful as you can pushback the object itself in an array.

  • Like 1

Share this post


Link to post
Share on other sites

@pierremgi Well im going to have a script save the objects, so that the playerbuilt fortifications stay around after restarts and what not.
However, the script that saves uses those kinds of variables to pick what whether to save something or not.
Whenever the save function kicks in, it will save stuff by checking stuff for this :
Examples
[“canBeMoved”, true] call
[“isLocked”, false] call 
[“isMedic”, false]

 

Hence why i want to be able to save fortifications by having "issandbag" or something like that applied to them.

Share this post


Link to post
Share on other sites

@sarogahtyp Hey finally tested it, while it may have worked, it sadly did not work exactly as intended, but that could also have been on me.
Do you have any knowladge of Hunterz persistance, it would also have to compatible with that.
It would seem the object can also be called by "_obj call Hz_pers_API_addCrate;"
Thing is, if i were to have it run with example "Land_sandbag_long_F call Hz_pers_API_addCrate;" I don't think it would recognize and save all sandbags.
I have read the resources Hunterz included in his work, and have gotten it to work with vehicles and such, but it sadly does not cover Vehicles very well.
Not actually asking anyone to read this just to help me.
But if someone does stumble by and is intrigued or think they might have a deeper understanding then me.
https://pastebin.com/xEqW4sJe
Outlined the most important section (the whole document is long, so i made /////// around the most relevant part)
 

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

×