Using function paramters to give objects targets.

0 favourites
  • 9 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I have 2 Enemy objects: Enemy 1 and Enemy2. It is a respawn game so there is always only one of each object at one time. Both enemies have an instance variable which determines their target. What I want to accomplish is having a function that gives them a new target everytime they die or they kill their target.

    What I tried was having the function

    EVENT - On FUNCTION

    • -- SUBEVENT1 - Parameter 0 = 1

    ------ SUBEVENT1A - If .... then Enemy1 set instance variable Target to...

    --- SUBEVENT 2 - Paramater 0 = 2

    ------ SUBEVENT2A - If .... then Enemy2 set instance variable Target to...

    on Enemy1 destroyed - call FUNCTION(1)

    But this does not work. The enemy keeps the same target that it had when it died. I also have:

    ON start of layout - Call Function(1) & Call Function(2) but this doesn't seem to work either.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You are setting an object's instance variable and than destroying an object, so obviously changes are not saved.

    Do it "On object create".

  • Well I do have it on a wait timer before it runs the call so it should respawn in time. But even calling on start of layout the function doesn't work. I believe it's my main sub events for the function that is the issue.

  • You are setting an INSTANCE variable which means it will be gone together with the instance of the object.

    You should provide some screens, so we could actually see what are you doing there.

  • Not sure why you insist on using a Function. If you really want too, i can show you.

    But. Consider this.

    'On x Destroyed' is allready a function with as parameter(0): the destroyd object. It gets called by a trigger, just automaticaly and with not headaches.

    See:

    https://

    drive.google.com/open?id=0B1SSuCVV8v74amROMHVHR3lKU28

  • Not sure why you insist on using a Function. If you really want too, i can show you.

    But. Consider this.

    'On x Destroyed' is allready a function with as parameter(0): the destroyd object. It gets called by a trigger, just automaticaly and with not headaches.

    See:

    https://

    drive.google.com/open?id=0B1SSuCVV8v74amROMHVHR3lKU28

    I have the enemy finding a new target when their target dies, when they die, and when they heal back up after retreating. So I'm using a function to save the hassle of writing that every time. I'll post screenshots in a second. Thanks for the response I'll see if I can use what you've given me.

  • You are setting an INSTANCE variable which means it will be gone together with the instance of the object.

    You should provide some screens, so we could actually see what are you doing there.

    First pic is my on start of layout event. The function is called but does not change the target. (please ignore the getTarget(1) it's no longer in my project)

    2nd pic is of my Enemy object and instance variable default at None.

    3rd pic is from preview mode. The object is not moving and I have text to show it's current target which is still None

    4th pic is the actual function code

    Note: Also the function DOES call at the start of layout because the text is set to CALLING during preview mode, but it does not set the target.

  • Problem solved. A friend found the issue, I'm missing an option for if both players health are above zero. SILLY ME! Thanks for the responses!

  • If object "Enemy" exists at the start of layout, then the "Target" instance variable will be set if any condition combination within the function is TRUE. I believe none of these conditions are TRUE when you run the function. Otherwise there's a C2 bug - which I doubt.

    Also keep in mind that you are changing the instance variable for currently existing object instances. You are not changing the default value, so once you destroy Enemy you have to set the variable again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)