Jump to content

variable name to all objects


AdirB

Recommended Posts

I wrote a lines of code which creates objects but I want these objects to be called all by one name so if I need to delete them in end() I will need only to type the variable of all of the objects instead of typing each one of them separately, there's pretty much of these.

I'd apperciate it if someone explains me how to do that.

Thanks in advance :)

Edited by AdirB
Link to comment
Share on other sites

8 minutes ago, Fenix2525WOT said:

All inherits from object so you have to call each one seperately

That means if when I want to delete them when the callout ends I have to call each one of them seperately?

I have 20 objects.

Edited by AdirB
Link to comment
Share on other sites

2 hours ago, AdirB said:

That means if when I want to delete them when the callout ends I have to call each one of them seperately?

I have 20 objects.

What do ypu mean telling "OBJECT"

If you don't know, proper object is this:

public static bool ReferenceEquals(object objA, object objB)
{
    return objA == objB;
}

 

header.png.584c28e8d611130062860b2efc498fc2.png

Los Santos Rescue Division Developer

CLICK HERE TO LEARN MORE

 

Link to comment
Share on other sites

Just now, Fenix2525WOT said:

What do ypu mean telling "OBJECT"

If you don't know, proper object is this:


public static bool ReferenceEquals(object objA, object objB)
{
    return objA == objB;
}

 

Vehicles for example.

            Vehicle PoliceVeh1 = new Vehicle("POLICE", new Vector3(-3001.16f, 111.4664f, 14.24027f), -67.54518f);
            Vehicle PoliceVeh2 = new Vehicle("POLICE3", new Vector3(-3009.934f, 124.5363f, 14.70165f), -135.2327f);
            Vehicle PoliceVeh3 = new Vehicle("POLICE3", new Vector3(-2994.135f, 110.3635f, 14.10404f), -116.5795f);

Instead of typing the three to delete I can make an array that contains these 3 and I can call this array PoliceVehs so I can type this instaed of typing these 3.

something like: 

PoliceVehs={
            Vehicle PoliceVeh1 = new Vehicle("POLICE", new Vector3(-3001.16f, 111.4664f, 14.24027f), -67.54518f),
            Vehicle PoliceVeh2 = new Vehicle("POLICE3", new Vector3(-3009.934f, 124.5363f, 14.70165f), -135.2327f),
            Vehicle PoliceVeh3 = new Vehicle("POLICE3", new Vector3(-2994.135f, 110.3635f, 14.10404f), -116.5795f)
};

It's obviously not right but maybe it will help me to explain myself.

Link to comment
Share on other sites

You're sorta there. If I'm not mistaken, you should be able to make a Vehicle array like that, then in the end, just make a loop that deletes every element in the array.

for(int i=0; i<3; i++)
{
  	if(vehicleArray[i] != null)
		vehicleArray[i].delete;
}

And you'd obviously have to use whatever code is needed to delete the car in place of vehicleArray.delete.

And the if statement isn't needed but I would strongly suggest it just in case one element gets deleted by another part of your code and then you won't have this code trying to delete a car that doesn't even exist.

Edited by Cosmo
Link to comment
Share on other sites

As far as I unnderstand I need to make an array called VehicleArray to use this method.

so it will be like this?

string[] VehicleArray =
{
private Rage.Object cone1,
private Rage.Object cone2,
private Rage.Object cone3,
private Rage.Object cone4,
private Rage.Object cone5,
private Rage.Object cone6,
private Rage.Object cone7,
private Rage.Object cone8,
private Rage.Object cone9,
private Rage.Object cone10,
private Rage.Object cone11,
private Rage.Object cone12,
private Rage.Object cone13,
private Rage.Object cone14,
private Rage.Object cone15,
private Rage.Object cone16,
private Rage.Object cone17,
private Rage.Object cone18,
private Rage.Object cone19,
private Rage.Object cone20
};

And then in the delete ( End() ) section of the LSPDFR API I can add the

for(int i=0; i < VehicleArray.length; i++)
{
  	if(vehicleArray[i] != null)
		vehicleArray[i].delete;
}

Did I get it?:sweat:

Link to comment
Share on other sites

Don't instantiate your array or List (I prefer Lists over Arrays) with your objects. Keep the declarations separate, and then add each entity to the list as you spawn them. Then in your cleanup or End() code, iterate through the list, and dismiss each entity, after checking if it exists.

See my inheritance example on the GitHub repo.

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...