Identifying an Object's Instance Variable in an Action

Trying to set up a movement system for an NPC in which they go randomly to one of several point. However, I am hoping to limit the number of unique objects I am using. Currently I have several objects called ‘PathMarker’ all of which have an instance variable of ‘marker_number’ set to a unique value (1,2,3, etc.).

Essentially the goal is to have a pathfinding behavior which moves a sprite to a ‘PathMarker’ object with the ‘marker_number’ (instance variable) value of X. Is it possible to use instance variables in this way? I can’t seem to build an action which allows me to call an object with a specific instance variable value.

Appreciate the insight.

Most conditions will “pick” the referenced objects like a filter. Most actions will then only affect them.

Example: left mouse choose object with ID variable of 1, right button picks a random one.
(The important thing is you check an object’s variable not a scene)

You could also track which ones are moving and only pick from the ones not moving.

You can also pick the closest object, this uses the mouseX,MouseY but you can use any value or variable.

I guess you could also use the pathfinder speed as a condition but I prefer the Boolean. I’m not sure if there’s a difference.

Just remember event order matters.

1 Like

I looked at your code again. The objects should have a fixed ID variable or unique. You can give them a number on creation, design time or using a [for each object]. Assigning a random number wouldn’t guarantee a unique number. You could get 1,2 or 2,2 or 1,1.

I use a [for each object] for a known or fixed quantity of objects.

This works best when you’re not creating and deleting objects. It’s easier to pick based on some other action than maintain objects unique IDs.


Huge help! I really appreciate the detailed reply and example screenshots. As a bonus your suggestion actually solved another issue I was having in your initial response. Many thanks.