Okay, first I'm going to rewrite your code how I would do it and then explain the differences. I'll put a ### before changes I made.
Code: Select all
plotscript, Map Auto Run 4, begin
###
variable(sl, slime, slParent, count)
count := 0
While ( current map == current map ) do(
slParent := lookup slice(sl:map layer0)
###
sl := load slice collection(whatever)
slime := load slice collection(whatever+1)
#This creates a ring of light around the slug
put slice (sl, camera pixel x, camera pixel y)
#This creates a trail of mucus behind the slug
put slice (slime, camera pixel x, camera pixel y)
set parent (sl, slParent)
set parent (slime, slParent)
move slice above (slime, sl)
wait
free slice (sl)
#This checks if the amount of mucus slices exceeds 10, and frees the exceeding slice
###
count := child count(slParent)
if (count >= 10) then(
free slice (first child (slParent))
)
)
end
Okay, so I eliminated the "collection" and "sliceNum" variables. Why did I do this? Well, you were using the collection in an interesting way, basically loading it and then splitting it into its component parts (a ring of light and a slime trail) and parenting each of those separately to the map layer. This is fine EXCEPT that you are actually abandoning an invisible slice container each time you do this. It may not actually matter that much but these things will never be garbage collected (until a map change I believe) and it would be better to do without them.
Thus I changed your code to load two separate slice collections (that you will now have to create... sorry about that) called "whatever" and "whatever+1" in the code that represent the ring of light and slime respectively. If these were just individual sprites, you can replace "load slice collection" with "load walkabout sprite" and/or "load large enemy sprite" or whatever rather than creating new collections.
The only other change I made was basically changing your "count := child count(slime)" to "count := child count(slParent)", slParent here referring to your chosen map layer.
Something to keep in mind is that this code will have to be modified if other stuff is being parented to map layer 0 at any time since that would of course change the slice children count and/or could result in non-slime-slices getting deleted.
Oh and disclaimer: I wrote all this stuff freehand without my compiler handy so you may have to clean up my syntax somewhat. I'm generally a "write it and let the compiler do the debugging" kind of programmer....