Jump to content

Array of Blips


cmPLX

Recommended Posts

Evening,

 

Forgive me for my lack of knowledge on this subject, coming from Self Taught programming. Trying to create an array of Blips for my Suspects. How would I go about initializing this Array so it does not return a NULL value when I want to use them?

 

Thanks,

 

cmPLX

 

Create my Blip Array

private Blip[] SuspectBlips;

Then when I create the Peds, I'm using this.

SuspectBlips[i] = this.drivebys[i].AttachBlip();

 

Edited by cmPLX
Link to comment
Share on other sites

Use a List, not an array. Lists are meant to have things added to them all the time. 

 

The way I'd do it is something like this:

 

List<Blip> blips = new List<Blip>();

for(var driveby in drivebys)
{
  Blip b = driveby.AttachBlip();
  b.Color = whatever;
  b.Name = whatever;
  blips.Add(b);
}

 

[REL] Coastal Callouts: An action-packed mod with new vehicles, maps, capabilities, and callouts in and around the waters of Los Santos

[REL] Police Tape: Make your scenes more realistic while stopping peds and traffic

[REL] Better EMS: Realistic and dynamic EMS response

Join the Parks Benefactor Program to support my work and get early beta access!

Link to comment
Share on other sites

Parks is right, in most cases when you don't know the actual runtime lenght of an array you should use another data structure. Your example doesn't work because you did not initialize your array = it doesn't have any values.

http://stackoverflow.com/questions/32290879/meanings-of-declaring-instantiating-initializing-and-assigning-an-object

Also, it seems to me you should replace AttachBlip() with a Blip constructor and pass an entity to it.

It should look this way:

private Blip[] SuspectBlips = new Blip[1];
SuspectBlips[0] = new Blip(drivebys[i]);

Array is fine when you know the lenght of your collection and/or write high performance code.

Edited by LtFlash
Link to comment
Share on other sites

6 hours ago, LtFlash said:

Parks is right, in most cases when you don't know the actual runtime lenght of an array you should use another data structure. Your example doesn't work because you did not initialize your array = it doesn't have any values.

http://stackoverflow.com/questions/32290879/meanings-of-declaring-instantiating-initializing-and-assigning-an-object

Also, it seems to me you should replace AttachBlip() with a Blip constructor and pass an entity to it.

It should look this way:


private Blip[] SuspectBlips = new Blip[1];
SuspectBlips[0] = new Blip(drivebys[i]);

Array is fine when you know the lenght of your collection and/or write high performance code.


Thanks PNWParksFan and LtFlash, this helped me a lot. I only have a max length of 3 for the array due to limited passenger seats. 

Edited by cmPLX
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...