ForumsProgramming ForumAS2 Problem with splicing

3 3383
nixon
offline
nixon
11 posts
Nomad

I'll try my best to describe my problem.
I've got a custom class, we'll call it 'hero'. This custom class has an array in it, we'll call the array 'enemies'. On a different custom class, called 'Enemy', I'm trying to figure out how to splice this instance of 'Enemy' out of the array "enemies" when it's destroyed. I know it's gotta be simple, but I've scoured the net looking for the correct way to code it, but I only found generic examples of splicing. Any help is appreciated, thanks.

  • 3 Replies
nixon
offline
nixon
11 posts
Nomad

Perhaps what would help is if I knew a good way to set an id for each enemy in the 'for' loop used to create them. Then I could probably use the id to get the splice to work right.

rjbman
offline
rjbman
215 posts
Nomad

Alright well I'm not used to AS2, but I'd think if I gave you the general idea, you could figure out the specific syntax.

I had a similar problem with a Visual Basic program. What I did was write a function that basically accepted two things: an array and an index. It then took the array, started at the index provided, then deleted it by moving all the other values down one.

i.e. [1 3 4 3 6 4 3 4 6 7] to get rid of the fourth one (3 in the index). Give it 3. It creates a variable to keep track of the count.

array[count] = array[count+1];
count++;


Hopefully that's close to what you're aiming.
nixon
offline
nixon
11 posts
Nomad

If I knew how to reference the object in the array I could do that and better. The 'for' loop creates the object in the 'hero' class. Over in the 'Enemy' class I'm trying to reference it without saying "splice 3", because whatever code I put into the 'Enemy' class is exactly duplicated for each enemy, so 1,2,3,4 would all say "splice 3". So if I could say "splice x" where x is that instance's position in the array, then I could put your plan into motion. I appreciate the thought, rjbman.

Showing 1-3 of 3