why why why!? 1319 = 0 ?

Post » Sun Nov 18, 2012 6:48 pm

float DrainMult = Myweapon.getbasedamage() / DaedricBow.GetBaseDamage()

debug.messagebox(Myweapon.getbasedamage() + " / " + DaedricBow.GetBaseDamage() + "Drain = " + DrainMult)

I get the message "13/19 Drain = 0"

It should be 13/19 = 0.6842105263157895.


Anyone have any idea what the "H-E Double Hockey Sticks" is going on with this?
User avatar
R.I.p MOmmy
 
Posts: 3463
Joined: Wed Sep 06, 2006 8:40 pm

Post » Sun Nov 18, 2012 3:40 pm

I've never used the CK before, but this is a common programming issue, known as integer division.

Basically, in most programming languages if you divide an integer by an integer then you get an integer out, the only way to fix this is to cast one of the integers into a float......but I have no idea how you do that in the CK.


EDIT:
Maybe this would work

float myWeaponDamage = Myweapon.getbasedamage()
float DrainMult = myWeaponDamage / DaedricBow.GetBaseDamage()
User avatar
Stephani Silva
 
Posts: 3372
Joined: Wed Jan 17, 2007 10:11 pm

Post » Sun Nov 18, 2012 11:55 am

I've never used the CK before, but this is a common programming issue, known as integer division.

Basically, in most programming languages if you divide an integer by an integer then you get an integer out, the only way to fix this is to cast one of the integers into a float......but I have no idea how you do that in the CK.


EDIT:
Maybe this would work

float myWeaponDamage = Myweapon.getbasedamage()
float DrainMult = myWeaponDamage / DaedricBow.GetBaseDamage()
How about storing the result as a float instead?
User avatar
Timara White
 
Posts: 3464
Joined: Mon Aug 27, 2007 7:39 am

Post » Sun Nov 18, 2012 5:47 am

As da mage says, http://www.creationkit.com/GetBaseDamage_-_Weapon is returning ints, so they just need to be casted as floats.

	Float DrainMult = MyWeapon.GetBaseDamage() As Float / DaedricBow.GetBaseDamage() As Float	Debug.MessageBox(MyWeapon.GetBaseDamage() As Float + " / " + DaedricBow.GetBaseDamage() As Float + "Drain = " + DrainMult)
...should read "13.00000/19.00000 Drain = 0.68421"
User avatar
Auguste Bartholdi
 
Posts: 3521
Joined: Tue Jun 13, 2006 11:20 am

Post » Sun Nov 18, 2012 5:37 am

How about storing the result as a float instead?
The result would be already calculated as a big, fat, round ZERO. Store/cast it afterwards won't change anything. The way to go is as da mage suggested.
User avatar
laila hassan
 
Posts: 3476
Joined: Mon Oct 09, 2006 2:53 pm

Post » Sun Nov 18, 2012 10:45 am

I just leaned a HUGE lesson, thanks to Da Mage (how is it I never had this issue in 6 years of scripting Oblivion?) Thanks JustinOther for the script sample as that did work!
Thank to the rest of you for trying to help.

As da mage says, http://www.creationkit.com/GetBaseDamage_-_Weapon is returning ints, so they just need to be casted as floats.

	Float DrainMult = MyWeapon.GetBaseDamage() As Float / DaedricBow.GetBaseDamage() As Float	Debug.MessageBox(MyWeapon.GetBaseDamage() As Float + " / " + DaedricBow.GetBaseDamage() As Float + "Drain = " + DrainMult)
...should read "13.00000/19.00000 Drain = 0.68421"
User avatar
Queen of Spades
 
Posts: 3383
Joined: Fri Dec 08, 2006 12:06 pm

Post » Sun Nov 18, 2012 4:55 pm

The result would be already calculated as a big, fat, round ZERO. Store/cast it afterwards won't change anything. The way to go is as da mage suggested.
It works in python at the very least.
>>> var1 = int(2)>>> var2 = int(345783745)>>> var3 = float(var1/var2)>>> print(var3)5.783961880567867e-09>>>
User avatar
gandalf
 
Posts: 3400
Joined: Wed Feb 21, 2007 6:57 pm

Post » Sun Nov 18, 2012 9:26 am

It works in python at the very least.

Variables in Python are not strongly typed. In other words, a Python variable can hold any type of value or object. But Papyrus follows a more traditional approach in that the variables are strongly typed and a particular variable can only hold values of its type. That is why, in Papyrus, this needs to be done the way da mage, JustinOther, and LukeH said.

ETA: It's probably more accurate to just say that Python handles data types much differently than most other languages. In Python you don't typically have to worry about data type. Other languages typically strictly enforce types and dividing two integers will produce an integer result. Papyrus follows this more typical model.
User avatar
Vera Maslar
 
Posts: 3468
Joined: Wed Sep 27, 2006 2:32 pm

Post » Sun Nov 18, 2012 8:28 am

If I remember correctly (and I certainly may not - it's been a while I've not been able to test this before writing this post), the language used in Oblivion and the Fallout games treated integers internally as floating point values, so although the final value would be truncated if assigned to an integer assigning the result of integer division to a float variable would have worked.

Cipscis
User avatar
Hilm Music
 
Posts: 3357
Joined: Wed Jun 06, 2007 9:36 pm


Return to V - Skyrim