Jump to content
PheNux Cam

deleteVehicle Loop?

Recommended Posts

Hi, trying to learn how to loop this command if that is what it requires.

 

Code: offroad = "B_G_Offroad_01_repair_F" createVehicle getMarkerPos "man2";

Code: deleteVehicle offroad;

 

I have a vehicle spawner and it works fine while being able to spawn as many as I want, the issue I have is that with this code I am only able to delete "one" object worth of that vehicle. So if I spawn in 3, it will only delete the 3rd one and not the other 2. I expect that I require some kind of loop command or an if and else, I have not learned how to use this properly. Currently studying the if and else statements to see if they are involved with this process, help is greatly appreciated thanks.

 

Currently working with this trying to figure it out, hopefully I'm in the right area of code, but seems like the "while" is meant to repeat code so this must be what I am looking for.

 

    while {offroad true} do
    {
        deleteVehicle offroad;
    };
    

Share this post


Link to post
Share on other sites

You can easily put the spawned vehicles inside an array using the delicious pushBack command, then delete every vehicle inside that array:

 

put this in the init.sqf or wherever, only needs to be executed once on mission start:

AllmyVehicles = [];

Then when spawning:

_offroad = "B_G_Offroad_01_repair_F" createVehicle getMarkerPos "man2";

AllmyVehicles pushBack _offroad;

//do this for all vehicles you spawn in and want to delete later

 

To delete all in one line:

{deleteVehicle _x} forEach AllmyVehicles;

 

Cheers

Share this post


Link to post
Share on other sites
6 minutes ago, Grumpy Old Man said:

You can easily put the spawned vehicles inside an array using the delicious pushBack command, then delete every vehicle inside that array:

 

put this in the init.sqf or wherever, only needs to be executed once on mission start:


AllmyVehicles = [];

Then when spawning:


_offroad = "B_G_Offroad_01_repair_F" createVehicle getMarkerPos "man2";

AllmyVehicles pushBack _offroad;

//do this for all vehicles you spawn in and want to delete later

 

To delete all in one line:


{deleteVehicle _x} forEach AllmyVehicles;

 

Cheers

 

Thank you I will work on it tomorrow. Also I have a question, can you explain to me what this is doing 

AllmyVehicles = [];

 I know that is a created variable but what is the []; <-- doing?

Share this post


Link to post
Share on other sites
27 minutes ago, PheNux Cam said:

 

Thank you I will work on it tomorrow. Also I have a question, can you explain to me what this is doing 


AllmyVehicles = [];

 I know that is a created variable but what is the []; <-- doing?

 

It makes the variable an array, see Data Types for more info.

Share this post


Link to post
Share on other sites

Like WaffleB said, it declares the variable "AllmyVehicles" as an empty global array.

So you can access it from within any script and fill it up with the pushBack command.

 

Cheers

Share this post


Link to post
Share on other sites
4 hours ago, PheNux Cam said:

 

Thank you I will work on it tomorrow. Also I have a question, can you explain to me what this is doing 


AllmyVehicles = [];

 I know that is a created variable but what is the []; <-- doing?

 
 
 

I am guessing from this question you are not just new to ArmA scripting you are new to the programming world altogether :) Now worries. I will explain it to you in simple terms.

 

Imagine the "AllmyVehicles" (your array) a basket of fruits and the _offroad (your variable) is a fruit.

 

When you created the AllmyVehicles = [ ] you basically just told the computer to make for you an empty basket that you will be using to store fruits in it.

 

Every time you "AllmyVehicles pushBack _offroad" you are basically adding another fruit to your basket. 

Share this post


Link to post
Share on other sites
3 hours ago, BlacKnightBK said:

I am guessing from this question you are not just new to ArmA scripting you are new to the programming world altogether :) Now worries. I will explain it to you in simple terms.

 

Imagine the "AllmyVehicles" (your array) a basket of fruits and the _offroad (your variable) is a fruit.

 

When you created the AllmyVehicles = [ ] you basically just told the computer to make for you an empty basket that you will be using to store fruits in it.

 

Every time you "AllmyVehicles pushBack _offroad" you are basically adding another fruit to your basket. 

 

 

Yes I am new to programming as  whole only a weeks time, thank you for making it clear :)

Share this post


Link to post
Share on other sites
56 minutes ago, PheNux Cam said:

 

Yes I am new to programming as  whole only a weeks time, thank you for making it clear :)

 

My pleasure. I am glad you decided to learn and you started with Arma, they make it so easy here. Once you get the basics it's all about creativity then. 

 

Enjoy :)

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

×