Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
Adressing Entities "dynamic" with a string
  • Lets say I have a multiple times spawning Entity, each one getting a unique string name (like Entity_1, Entity_2...). Now there is something happening with one of them (like it collided or something) and I managed to catch their exact name in a string-property in another Entity. How would the code look like, if I want ro change a property inside of the spawned Entity (like the sprite animation) from the other Entity?

    I tried:

    Doesn't work that way sadly... any ideas?
  • 5 Comments sorted by
  • @Cavaron you will need to grab a reference to the entity object dynamically by setting the Entity object on a dynamic property then you should be able to reference the components on that dynamic property.

    So create a property called "EntityObject" on the DataContainer then use a Change Property action to set that EntityObject property to a reference of the entity dynamically using an expression like this:

    Entity[ Self.DataContainer.EntityName ]

    Then you should be able to access the components on the dynamically referenced entity via a Change property action like this and change the "currentAnimationName" value using a property reference:


    **NOTE: This can create a memory leak if you do not remove the reference to the entity using that dynamic property "EntityObject". Either destroy the entity this property is on or set it to something else when done using it otherwise if the entity being accessed is destroyed it will never get removed from memory. 

    I haven't tested this because it is a bit of a workaround but give it a try.
  • Maybe I did it wrong, but after a bit of testing - my guess is, that you can't set a property dynamically with the Find In Range-action, because the Game.CurrentActionData seems to just pass values bidirectional, but don't transmit... well, the real "adress" this values are comming from.
    So if I referenced something like "" it will really point to the Game.CurrentActionData.foundEntity (which will work only for one time step) and not the found Entities real name behind it (which would work permanently).

    It would be great being able to use variables in the pointer-fields, because I already did a property in each spawned Entity which contains their names as strings. I could read them out with the Game.CurrentActionData and use them from there on if I want to do anything with the found Entity (like let it battle the Entity which found it until anyones health runs out).

    Or there is already a better way to do it and I don't see it. Wouldn't be the first time ;)
  • Hm... I have to correct myself - my problem seems to be that the persistent constrain action fired from inside a "rules map" action loses it's persistens if the rules conditions are not met any longer. Is that intended? I thought a persistent action is... uhm... persistent ;)

    Edit: after consulting the manual - it seems to be. Then I guess I will have to work around that with a variable starting another rule to constrain as long as the variable is valid. This is getting complex (a rule for detect enemys only if not already in a fight, a rule to determine where to walk for a fight, a rule to start the fight when reaching the position, a rule to check a global data container if the found enemys health has run out...). For the future - is it possible to have a checkbox in the constrain action (like "bind constrain to rulesmap conditions")?

    Thinking more about that - doesn't this mean that it is impossible to constrain a property from the CurrentActionData.foundEntity in my desgin, because the "find in range"-action needs to be in a rules map. That is, because the searching entity could find another target bevore the battle is done with the first one found, so I have to stop the the "find in range"-action from firing and with it all the other actions inside the rule...
  • @Cavaron there may be an easier way to go about this. I just haven't had the chance to sit down and go through this. I will get back to you on this however. Just letting you know I'm not ignoring this post.
  • @Lavon thanks for the reply. Maybe you can have a look at my related request #1229 about the "find in range" actions behavior (or my inability to understand it ;). Take your time, no hurry. I will focus on designing more graphics first.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion