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

Bugs will be moved here once resolved.

Post » Wed Aug 03, 2016 2:27 pm

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. :-)

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
B
48
S
13
Posts: 111
Reputation: 3,864

Post » Mon Aug 08, 2016 11:06 am

Thanks, should be fixed in the next build.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,694


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests