HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: (resolved)Unstable external function  (Read 1088 times)

GlorianLanTarini

  • General Accounts
  • *
  • Posts: 148
    • View Profile
(resolved)Unstable external function
« on: Feb 17, 17, 07:09:04 AM »

I use NormalizeVector3 function to quick calculation of direction, like this:

Code: [Select]
direction as Vector3 = tgtPos - myPos
NormalizeVector3(direction, direction)

But very often I get this error:

SCRIPT ERROR: Exception UsageException in function 'NormalizeVector3' invalid numeric result

How to lower chance of this error, or maybe there is another method for quick calculations of directions?
« Last Edit: Feb 18, 17, 01:24:19 AM by GlorianLanTarini »
Logged

Mr_Conflicts

  • General Accounts
  • *
  • Posts: 32
  • Client Programmer
    • View Profile
    • Daniel J. Burkhart
Re: Unstable external function
« Reply #1 on: Feb 17, 17, 10:22:52 AM »

I would recommend looking at this wiki page to see all the vector related functions provided in Hero Engine. I would use the vector length as the wiki example shows to get distance.

Code: [Select]
point1 as Vector3 = myPos
point2 as Vector3 = tgtPos
dist as float = VectorLength(point1 - point2)

As for the error, I am not sure  as to what the error message means, but maybe its because you are  using the same input value as the output value. (I am not 100% on this but its just a guess, hopefully someone can confirm or deny this.)
Logged
Anvil of Honor - Client Programmer

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Unstable external function
« Reply #2 on: Feb 17, 17, 10:24:39 AM »

A guess, but maybe that happens when your tgtPos and myPos are the same, leading to a vector that is all zeroes and thus can't be normalized.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO
Re: Unstable external function
« Reply #3 on: Feb 17, 17, 02:14:03 PM »

A guess, but maybe that happens when your tgtPos and myPos are the same, leading to a vector that is all zeroes and thus can't be normalized.

most likely this. I had this problem as well when I first didnt exclude my character so my ray was hitting the character at the exact spot it started.

One thing i have learned about HSL is you should always check for == 0 and leave yourself a scripterrorandcontinue() then return.

You can always come back to it and now you have a nice little note.

GlorianLanTarini

  • General Accounts
  • *
  • Posts: 148
    • View Profile
Re: Unstable external function
« Reply #4 on: Feb 17, 17, 11:21:16 PM »

As for the error, I am not sure  as to what the error message means, but maybe its because you are  using the same input value as the output value. (I am not 100% on this but its just a guess, hopefully someone can confirm or deny this.)

Nope, it can't be a reason, because I take this maneuver from clean engine script, where it work fine.

And it work fine for me, when I use it ones. But, also I use it repeatedly in projectile chasing target mechanic.
A guess, but maybe that happens when your tgtPos and myPos are the same, leading to a vector that is all zeroes and thus can't be normalized.
most likely this. I had this problem as well when I first didnt exclude my character so my ray was hitting the character at the exact spot it started.

One thing i have learned about HSL is you should always check for == 0 and leave yourself a scripterrorandcontinue() then return.

You can always come back to it and now you have a nice little note.

As I say, I get this error (some time massively) when projectile chasing target. And I has check - chasing is done when position is same. But still get errors. I should dig it some more. Maybe change something in projectile's mechanic.

Anyway, thanks for replies.
« Last Edit: Feb 17, 17, 11:22:56 PM by GlorianLanTarini »
Logged

GlorianLanTarini

  • General Accounts
  • *
  • Posts: 148
    • View Profile
Re: (resolved)Unstable external function
« Reply #5 on: Feb 18, 17, 01:31:02 AM »

I change this code

Code: [Select]
if myPos = tgt_pos
  me.ChasingComplete()
.

to this

Code: [Select]
if myPos = tgt_pos
  me.ChasingComplete()
  return
.

and error is stopped.

I have destructor in method ChasingComplete(), so I thought "return" isn't necessary. Sadly I was wrong.
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1138
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: (resolved)Unstable external function
« Reply #6 on: Feb 19, 17, 01:44:21 PM »

I have found need of "return" at times also. The best place to check is when the section of code is inside a function and the function continues with more code after. Some times it can be a loop. One place its not really needed would be at the end of the function itself, unless that function was called from another and code follows after.
Logged

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO
Re: (resolved)Unstable external function
« Reply #7 on: Feb 19, 17, 03:04:53 PM »

Return ends a function and returns to the caller.

Having return in ChasingComplete() stops that function and returns it to the caller which in this case is the next line of the if statement.