Turret Behaviour - Tricky "Unacquire Target" in "On Shoot"

0 favourites
  • 2 posts
From the Asset Store
Tricky Brick - Addictive classic game - Full game to post google store.
  • Problem Description

    "Unacquire Target" action in a "onShoot" condition displays error message

    Attach a Capx

    https://drive.google.com/open?id=0B2syU ... klMNlJBY0E

    Description of Capx

    If the "Unacquire Target" action is called from the "On Shoot" condition the below error message is shown:

    "Javascript error!

    Uncaught type error: Cannot read property 'x' of null

    http://localhost:50003/Turret_behaviour.js, line 390 (col 40)"

    By looking at the code, onShoot trigger is called in line 387, executing the UnacquireTarget function

    and setting "this.currentTarget = null".

    After that, in line 390, since it returned from the trigger with a null object, the tick loop

    tries to access the currentTarget.x property of this null object. I hope I was able to explain

    it properly. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":-)" title="Smile">

    To fix it, just replace lines 390 and 391 with an extra validation:

    // checking again if the currentTarget exists after the onShoot trigger was called

    if (this.currentTarget) {

    this.oldTargetX = this.currentTarget.x;

    this.oldTargetY = this.currentTarget.y;

    }

    ____

    Steps to Reproduce Bug

    • Create an event that acquires a target after a click or touch
    • Create a "on shoot" turret condition with a "unacquire target" action.

    Observed Result

    The message error above is displayed

    Expected Result

    No error message

    Affected Browsers

      [YES] Chrome: (YES/NO) [YES] FireFox: (YES/NO) [YES] Internet Explorer: (YES/NO)

    Operating System and Service Pack

    Windows 7 x64 SP1

    Construct 2 Version ID

    Beta r232

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, should be fixed in the next build.

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