Really Confused (Floats, GetAV(), etc..)

Post » Wed Jun 20, 2012 5:52 am

Hi,

I hope someone can clear things up a bit for me...

I'm trying to write a script that obtains a skill value, a perk, and do some calculations based on that.

After searching here on the forums and checking the CK wiki, the functions to do that seem pretty obvious. Here is my code, with "(...)" meaning that in the middle is something that should not be relevant at all:

Scriptname KRPHealing extends ObjectReference(...)Int Property Porcentaje Auto(...)Event OnActivate(ObjectReference akActivator)	Float SkillSpeech = Game.GetPlayer().GetAV("Speech") As Float	if(Game.GetPlayer().HasPerk(Haggling01))		Porcentaje = 10	endif	if(Game.GetPlayer().HasPerk(Haggling02))		Porcentaje = 15	endif	if(Game.GetPlayer().HasPerk(Haggling03))		Porcentaje = 20	endif	if(Game.GetPlayer().HasPerk(Haggling04))		Porcentaje = 25	endif	if(Game.GetPlayer().HasPerk(Haggling05))		Porcentaje = 30	endif	Float Factor = (3.3 - (1.3 * SkillSpeech/100)) As Float	Float Modificador = (1 / (1 + Porcentaje)) As Floatdebug.notification("F: " + Factor)debug.notification("M: "+ Modificador)debug.notification("P: " + Porcentaje)	if(!Game.GetPlayer().IsSneaking())(...)

The thing is that the output is the following:
F: 3.3
M: 0.000000
P: 20

The only correct output would be "P", as I've got Haggling at 3/5. Obviously Speech is NOT 0.0, so both "F" and "M" should have a different value.

While doing some modifications I got "M" to output "0.04" somehow, but after some editing it just went back to 0.0, and I'm completely unable to get it working. I don't know if this is some kind of CK bug, or if I'm missing something here.

I tried defining the variables as Float at startup also, with same result.

Thanks in advance.
User avatar
hannaH
 
Posts: 3513
Joined: Tue Aug 15, 2006 4:50 am

Post » Wed Jun 20, 2012 11:22 am

Hi,

I hope someone can clear things up a bit for me...

I'm trying to write a script that obtains a skill value, a perk, and do some calculations based on that.

After searching here on the forums and checking the CK wiki, the functions to do that seem pretty obvious. Here is my code, with "(...)" meaning that in the middle is something that should not be relevant at all:

Scriptname KRPHealing extends ObjectReference(...)Int Property Porcentaje Auto(...)Event OnActivate(ObjectReference akActivator)	Float SkillSpeech = Game.GetPlayer().GetAV("Speech") As Float -> No need to cast an Actor Value as a Float as they are already floats.	if(Game.GetPlayer().HasPerk(Haggling01)) -> this entire section should use Elseif to conditionalize which % to set as there is no need to check vs every single perk every time it runs		Porcentaje = 10	endif	if(Game.GetPlayer().HasPerk(Haggling02))		Porcentaje = 15	endif	if(Game.GetPlayer().HasPerk(Haggling03))		Porcentaje = 20	endif	if(Game.GetPlayer().HasPerk(Haggling04))		Porcentaje = 25	endif	if(Game.GetPlayer().HasPerk(Haggling05))		Porcentaje = 30	endif	Float Factor = (3.3 - (1.3 * SkillSpeech/100)) As Float -> also no need to cast anything as everything are already floats, casting a skill as a float when it is ALREADY a float maybe short circuiting the return as "0" instead of your actual skill value, and multipling 1.3 to 0 = nothing so you end up with 3.3 no matter what.	Float Modificador = (1 / (1 + Porcentaje)) As Float -> should just declare % as a float to begin with as it makes no difference to the script functionality, also there is no need to Cast the entire return to a float (which is where I believe your issue is) as the game/ck has zero issues with you running math functions on different variable types as long as they are numerical values.debug.notification("F: " + Factor)debug.notification("M: "+ Modificador)debug.notification("P: " + Porcentaje)	if(!Game.GetPlayer().IsSneaking())(...)

The thing is that the output is the following:
F: 3.3
M: 0.000000
P: 20

The only correct output would be "P", as I've got Haggling at 3/5. Obviously Speech is NOT 0.0, so both "F" and "M" should have a different value.

While doing some modifications I got "M" to output "0.04" somehow, but after some editing it just went back to 0.0, and I'm completely unable to get it working. I don't know if this is some kind of CK bug, or if I'm missing something here.

I tried defining the variables as Float at startup also, with same result.

Thanks in advance.
User avatar
James Shaw
 
Posts: 3399
Joined: Sun Jul 08, 2007 11:23 pm

Post » Wed Jun 20, 2012 10:03 am

Thanks for your reply SaidenStorm,

This is really confusing anyway. As I stated before, I tried also to not declare floats here and there, and this final code try (the one I posted) was after looking at a post from a BS developer, that had a line with a "float x = yyyy as float".

Now, I'm even more confused, if not desperate, because I have the two following simple lines:

Float Property Modificador Auto	Modificador = (1 / (1 + Porcentaje))debug.notification("M: "+ Modificador)debug.notification("P: " + Porcentaje)

"P" outputs "20", which is correct, but "M" outputs 0.0000.... which doesn't make any sense.
1 / (1 + 20) is NOT 0.0000

Thanks again.
User avatar
louise tagg
 
Posts: 3394
Joined: Sun Aug 06, 2006 8:32 am

Post » Wed Jun 20, 2012 6:35 am

Try this:

Modificador = (1.0 / (1.0 + Porcentaje))

That will tell the engine that you want the stuff on the right side of the "=" to be treated as a float rather than an integer.
User avatar
BrEezy Baby
 
Posts: 3478
Joined: Sun Mar 11, 2007 4:22 am

Post » Wed Jun 20, 2012 9:35 am

Try this:

Modificador = (1.0 / (1.0 + Porcentaje))

That will tell the engine that you want the stuff on the right side of the "=" to be treated as a float rather than an integer.

Nothing...

Before reading your post while still trying things I tried to assign "Porcentaje = 10.0", and "Float Factor = (3.3 - (1.3 * SkillSpeech/100.0))", but I didn't realize about the line you mentioned.

I tried it, but it still is the same. I managed to get "M" to 0.04 when I declared "Porcentaje" as Float instead as Int. But my problem right now is that "Game.GetPlayer().GetAV("Speech")" returns 0.00.
Even Game.GetPlayer().GetActorValue("speech") returns 0.00. I get NO value for my Speech skill. So my "Factor" value is 3.3 always ( (3.3 - (1.3 * 0/100)) = 3.3 )

I even tried to add this simple line on the "OnItemRemoved()" event for my quest:
Debug.Notification(Game.GetPlayer().GetActorValue("speech"))

It runs, but it's 0.000

Based on the examples I saw around, that's the way you get the player's value on certain skill... :wallbash:
User avatar
lauren cleaves
 
Posts: 3307
Joined: Tue Aug 15, 2006 8:35 am

Post » Wed Jun 20, 2012 11:03 am

I tried it, but it still is the same.

That's strange, because...

Float testInt test2test2 = 20test = (1.0 / (1.0 + test2))Debug.Notification(test)

...prints out the correct answer for me.

But my problem right now is that "Game.GetPlayer().GetAV("Speech")" returns 0.00.

Based on the examples I saw around, that's the way you get the player's value on certain skill... :wallbash:

According to http://www.creationkit.com/Actor_Value, try "Speechcraft" instead of "Speech"
User avatar
Yung Prince
 
Posts: 3373
Joined: Thu Oct 11, 2007 10:45 pm

Post » Wed Jun 20, 2012 5:35 am

This works
Scriptname YourScriptName extends ObjectReferenceFloat PorcentajePerk Property Hag00  AutoPerk Property Hag20  AutoPerk Property Hag40  AutoPerk Property Hag60  AutoPerk Property Hag80  AutoEvent OnActivate(ObjectReference akActivator)Float SkillSpeech = Game.GetPlayer().GetAV("Speechcraft")Debug.Notification("SS: " + SkillSpeech)If Game.GetPlayer().HasPerk(Hag80)Porcentaje = 30Elseif Game.GetPlayer().HasPerk(Hag60)Porcentaje = 25Elseif Game.GetPlayer().HasPerk(Hag40)Porcentaje = 20Elseif Game.GetPlayer().HasPerk(Hag20)Porcentaje = 15Elseif Game.GetPlayer().HasPerk(Hag00)Porcentaje = 10EndifFloat Factor = (3.3 - (1.3 * (SkillSpeech/100)))Float Modificador = (1 / (1 + Porcentaje))Debug.Notification("F: " + Factor)Debug.Notification("M: "+ Modificador)Debug.Notification("P: " + Porcentaje)EndEvent
User avatar
Jessica Raven
 
Posts: 3409
Joined: Thu Dec 21, 2006 4:33 am

Post » Wed Jun 20, 2012 1:18 am

This works

OK, looking at that code I see that my problem was that the skill isn't "speech", but "speechcraft". Thanks. Is there a place to check the "official" skills list?

Now Factor value returned is ~2.2.

(I see you corrected that " !Game.GetPlayer().HasPerk(Hag80) " :tongue: )

Thanks for all the help! Now I'm just polishing some wrong calculations here and there, but it seems it works now... finally... I can't believe that a code as easy as this took so many hours, just because of some "floats" here, and some ".00" there.... :wacko:
User avatar
oliver klosoff
 
Posts: 3436
Joined: Sun Nov 25, 2007 1:02 am


Return to V - Skyrim