Using Actor Value to Determine/Kill Oldest Actor

elvistjester

  • Posts: 34
Hi all,

I understand the difference between actor attributes and actor values.  However, I've been trying to use them to create an "Age" Actor Value.  In this way I hope to be able to kill the "oldest" or earliest created actor of a specific type.

LENGTHY EXPLANATION TO FOLLOW:
The game I am currently working on is "step" based.  Everything happens in "1 second steps" using the trigger event in behavior blocks.  Player input, enemy movement etc. is only processed or enabled during these steps.  My scene behavior has a custom "step" event.  During this event player movement is triggered based on previous input, and a new instance of a particular actor type is created.  There are many of these actors on screen and they are all of course running the same behavior.  I would like to kill the oldest actor on screen during each of these Step events.  It also seems ideal to increment each currently existing actor's "age" by one at this time, and once an actor's age exceeds a preset maximum: kill that actor.  I can't use an attribute though, as each actor would then share the same age, regardless of when they were created.

I've been trying to use the set/get Actor value blocks to do this with no success or sign of progress.  I am certain the error is mine, but scouring the web and this forum has not helped at all. 

Any help at all would be appreciated, Thanks!

ohlin

  • Posts: 71
Could you perhaps add them all to a list in their 'when created' part, and then start killing them off using that list?

elvistjester

  • Posts: 34
Hi!  I possibly could, but I've run into walls trying that as well. 

I might be overthinking it, but I don't know what apecifically to add to the list when created.  So I tried creating a custom block in my scene behavior that, using a code block, would get an actor's instance ID. I then tried adding that ID to the list.  Obviously instead of age, once my number of items in list exceeded the desired age of the actors, I could get the value from the position 0 of the list, but then I didn't know what to do with it.  Put the data at entry #0 into an attribute?  But which type?  A number?  an Actor?  As near as I can tell,the kill block only accepts actor attributes, code blocks, or self.

Removing the data from the top of the list is easy, but I can't figure out how to kill an actor from the list, or really what kind of identifier to add to the list so that it can be used later.

I very much appreciate the reply, I am definitely interested in solving this.

Innes

  • *
  • Posts: 1960
I might be overthinking it, but I don't know what apecifically to add to the list when created.

I may have over-simplified your problem, but I understand that you want to create several actors, and then be able to kill the oldest actor on demand.

My sample scene behavior code below creates an actor every time the Enter key is pressed. The newly created actor is then assigned to the 'my Last Actor Created'  Actor attribute. This attribute is then added to 'myActorList', which is an attribute of type List.

When the 'up' key is pressed, the [kill] block references the first item in the list (which is an actor) and kills it. The item is then removed from the list. The first item in the list is always the oldest actor.

The [when created] event initialises the list.

Side note: I was trying to figure out if it was possible to add the last created actor into the list without the intermediary step of assigning it to an actor attribute, but I couldn't figure it out. Does anyone know if this is possible? I was hoping to find a [Last Created Actor] block!
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

panda84

  • Posts: 28
Innes there is a block for getting the last created actor etc. under 'Scenes' -> 'Actors' under the title 'Get Actor' it's the first block there.

ohlin

  • Posts: 71
This is my solution, each second the oldest actor gets killed.

EDIT: Seeing what Innes did I can see that my whole "createdactors attribute" and "killnumber attribute" are obsolete. Of course if you remove the oldest item in the list, the second oldest automatically becomes the oldest and so on. Being new to this, I kind of thought that removing an actor from the list created a "hole" that would be filled by the newest actor created, and then messing up the order in the list.

« Last Edit: February 04, 2015, 05:42:14 pm by ohlin »

Innes

  • *
  • Posts: 1960
Innes there is a block for getting the last created actor etc. under 'Scenes' -> 'Actors' under the title 'Get Actor' it's the first block there.

Thanks; I knew it must be there - I had convinced myself it was a blue block, so over-looked it! Unfortunately, it appears to be unsearchable.

My revised example is attached.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

ohlin

  • Posts: 71
Innes, why does my list work even though I don't set it to 'create new list'?

elvistjester

  • Posts: 34
Wow!  Thank you guys so much!  This is one of the reasons I love Stencyl so much; this great community.  You guys are life savers.  I very much appreciate the help.

Thanks again!

Innes

  • *
  • Posts: 1960
Innes, why does my list work even though I don't set it to 'create new list'?

If you don't set it to 'create new list', you should get a #1009 error. If you don't get that error, then I can only guess that you added at least one item to the list in the attributes panel. If not, then I don't know the answer!
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

ohlin

  • Posts: 71
I get no error and nothing is set in the panel, so I guess this is a case for Mulder and Scully. Anyways, thanks for the answer! :)