Get Actor by Name

1MrPaul1

  • *
  • Posts: 1268
This is a custom block that converting name of the actor as text to the actortype attribute.

Allows you to create actors from list and makes your behaviors simple and short.

Search for "GetActorByName" behavior on Stencylforge

hezlym

  • Posts: 3
Can you provide a sample on how to use the behaviour?  I have multiple instances of an Actor Type in a scene and I need to know when user click on the instance, I need to know which one of the instance the user has clicked on.  I have renamed each instance with a difference name at the scene-inspector.  Now i need a function and a code to read the name of the instance when the user click on it.  Please help

captaincomic

  • *
  • Posts: 6109
I think that behavior is for getting an Actor Type by name, not a specific actor instance. (Btw. the block for that will be in the core palette in 3.1.)

The name field in the scene inspector is currently unused.

What do you want to achieve? Usually, for clicking on an actor you would create an actor behavior and there you can just refer to the actor as "Self".

hezlym

  • Posts: 3
In my scene, I have 6 instances of an Actor Type and when the user clicks on each of them, i need to know which one he clicks as he will get different points and I need to match the answers.  So If the instances have an ID or a Name like A, B, C, D, E and F, if when the user clicks and returns a D, then i know which he clicks and can give points to him accordingly.

Is there a solution around it?  Other than creating 6 different Actor Types?  I may later have say 20 instances on the same scene.

Please help

captaincomic

  • *
  • Posts: 6109
Yes, you can do that without an explicit ID. How to do it exactly depends on whether you place the actors in the scene, or you create them with the "create actor ..." block.

For example, if you place the actors in the scene it's easy: create an actor behavior, and an attribute Points, attach it to the actors, and customize the actors to set the Points attribute to the value each actor is worth.
Then in the use the following blocks.
  <when mouse is presses on Self>
     <set High Score to <<High Score> + <Points>>>

(Assuming High Score is a game attribute.)

If you really want to work with IDs instead, while the actor name is currently not used, you can also access an actor's ID with the following code:
Code: [Select]
actor.IDAnd then get an actor with
Code: [Select]
getActor(ID);

hezlym

  • Posts: 3
Awesome!.. it worked.  Used the the first way..  :) :) :)

Minimo

  • Posts: 201

« Last Edit: April 15, 2015, 01:09:46 am by Minimo »

DJEmergency

  • Posts: 170
I'm trying to figure out how I would use this to put a collided actor's name into a list. Is there any examples for this?

DJEmergency

  • Posts: 170
I think that behavior is for getting an Actor Type by name, not a specific actor instance. (Btw. the block for that will be in the core palette in 3.1.)

The name field in the scene inspector is currently unused.

What do you want to achieve? Usually, for clicking on an actor you would create an actor behavior and there you can just refer to the actor as "Self".

I don't see the block for this. Am I missing something?