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

Author Topic: (resolved) math script error?  (Read 1391 times)

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
(resolved) math script error?
« on: Nov 21, 16, 08:22:53 PM »

In a server side script, I have a simple calculation of 5 / 10. I print this number out as a float, it shows 0. I can understand if I used round() or truncate() that it would be 0, but it seems to be doing this anyway. I am trying to put in a variable radius.

Code: [Select]
  myrad as Float = 5/10
  println("rad = "+ myrad)
  var targets = GetTargetsInSphere(true, true, playeracct.GetPosition(), myrad)     // meter radius

it should print    rad = 0.5

I put the number in directly, and it show correctly, but I still get the error below:

Code: [Select]
  myrad as Float = 0.5
  println("rad = "+ myrad)
  var targets = GetTargetsInSphere(true, true, playeracct.GetPosition(), myrad)     // meter radius

it prints correct as     rad = 0.5

I am getting the following error because of the above:
SCRIPT ERROR: In function GetTargetsInSphere: GetTargetsInSphere cannot be called with a radius less than 0.
« Last Edit: Nov 21, 16, 11:16:34 PM by Thazager »
Logged

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO
Re: math script error?
« Reply #1 on: Nov 21, 16, 09:05:12 PM »

i think its = (5/10) otherwise it thinks it is a string.

as for the second part i think it has to be a whole number not a float or it has to have at least a value greater than 1. I remember dealing with that a while ago but it is something along those lines. try 1.5

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: math script error?
« Reply #2 on: Nov 21, 16, 09:49:22 PM »

I tried adding the () so that rad = (5/10) with no difference. Putting 1.5 directly into the getTargets() function works as does putting in 0.25 directly. So, it does take numbers under 1, but cant seem to calculate that float value.

Code: [Select]
  var targets = GetTargetsInSphere(true, true, location, 0.25)    // works

I believe something is possibly wrong with the math here, a typo maybe in the MATH script?
Maybe even the checks for the function to work?
Logged

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO
Re: math script error?
« Reply #3 on: Nov 21, 16, 10:47:05 PM »

I am at a loss then! :(

Will try to dig around a little with this. Maybe set the float to 0 then assign it:

rad as float = 0
rad = (5/10)

something does seem to be wrong but there are still a few other ways you can write this that might yield something.

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: math script error?
« Reply #4 on: Nov 21, 16, 10:48:32 PM »

i believe that for 5 and 10 they are integer literals and so it does integer division which gives 0.  As 5.0/10.0 you would get the proper fraction.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: math script error?
« Reply #5 on: Nov 21, 16, 11:10:55 PM »

Thanks, that was it.

Even when assigning the value to be a float, the integer literal overrode the Float type cast.
(seems weird to me that it does that)
Logged