Calling a decimal number as a short vs. float

Post » Fri May 27, 2011 6:42 pm

I've been doing an overhaul of one of my companions leveling scripts, and I noticed that all of the values are called as shorts in the script (it's modified from Grumpy's Companion 1.1). Now, some of the calculations involve multiplication, so the results are going to have decimals. So, what happens to the short variable? Does it truncate the number to the nearest whole number, or does it skip the decimal place (like a long does) and turn it into a huge number?
User avatar
brandon frier
 
Posts: 3422
Joined: Wed Oct 17, 2007 8:47 pm

Post » Fri May 27, 2011 8:57 am

well if it works anything like accuracy in chemestry, calculations would go under the more complete 'long' definition and the final output would be constrained by the short. Can't give a better answer though.
User avatar
brenden casey
 
Posts: 3400
Joined: Mon Sep 17, 2007 9:58 pm

Post » Fri May 27, 2011 8:55 pm

Another question I have is whether or not skills and attributes will even take a float variable. I know in MWSE, xGetBasWil for example, returns the base willpower of the npc, and it's called as a float. If you call it as a long, it returns an extremely huge number and messes up the script (it compiles fine, but you don't get exactly what you're expecting if you're running the script). It seems that in regular MW scripting, all these stats are handled as shorts however.

This script is not an MWSE script, I'm just comparing because I'm curious.
User avatar
Kayla Keizer
 
Posts: 3357
Joined: Tue Dec 12, 2006 4:31 pm

Post » Fri May 27, 2011 8:08 pm

I've been doing an overhaul of one of my companions leveling scripts, and I noticed that all of the values are called as shorts in the script (it's modified from Grumpy's Companion 1.1). Now, some of the calculations involve multiplication, so the results are going to have decimals. So, what happens to the short variable? Does it truncate the number to the nearest whole number, or does it skip the decimal place (like a long does) and turn it into a huge number?

I know for certain that it rounds when converting from a float to a short using `set x to y`. I am not sure how it rounds it although I think it is the nearest integer. Don't take that as fact though.

long lfloat f;...set l to f ;rounds 


Regarding what happens when using functions, I don't know. I seem to remember that you got very strange results with using either setPos or position with short arguments. I am not sure why it occurred and it could have been that the value I was trying to represent was too large to fit into a short (quite possible).

Another question I have is whether or not skills and attributes will even take a float variable. I know in MWSE, xGetBasWil for example, returns the base willpower of the npc, and it's called as a float. If you call it as a long, it returns an extremely huge number and messes up the script (it compiles fine, but you don't get exactly what you're expecting if you're running the script).

It may be because MWSE treats the long as a float. C and C++ allow you to treat one type as another type. It is possible to treat a block of memory holding a long as a float and due to the format differences you will end up with strange number.
User avatar
Rob
 
Posts: 3448
Joined: Fri Jul 13, 2007 12:26 am

Post » Fri May 27, 2011 8:49 pm

Thanks for the info! It would be handy to know if it rounds or just truncates the number at the decimal for my calculations, but the different is probably negligible. It does mean the companion won't see any skill raises until the player is at least level 12, but that's ok. A lower level player would have less to teach the companion. ;)

The actual calculation is ( companionskill + ( playerlevel * 0.6 ) or an equally small percentage. This means the companion's skills only get raised a few points at most per player level, because otherwise the companion's skills would increase exponentially as the player gains levels.
User avatar
Dagan Wilkin
 
Posts: 3352
Joined: Fri Apr 27, 2007 4:20 am

Post » Fri May 27, 2011 2:50 pm

I'm not sure if that is only part of the equation, but how about this.

companion skill gain = 1[(player skill - companion skill) * 0.6] + 2[player level * 0.6], where companion skill gain is equal or greater than 0, and companion skill gains are added at player level-up.

1 - this would simulate the player teaching the companion
2 - this would simulate the companion naturally gaining experience

Or those could be broken up into natural leveling and a defined teaching session given by the player.
User avatar
Genevieve
 
Posts: 3424
Joined: Sun Aug 13, 2006 4:22 pm

Post » Fri May 27, 2011 7:23 pm

Actually, it's already separated into defined teaching systems vs. "natural" leveling due to gaining experience with the player. The teaching system mods the skill by a few points manually, which is why the new skill level needs to be checked for every time the leveling script runs. The leveling script only handles the natural skill increases, which is why I want the gains to be somewhat miniscule, because there's other mechanics to help the companion gain skills as well.

I've also capped the skill increases at 100. If they go over, they're set back down to 100 again. It would take a long time to get the companion's skills up to 100 though.
User avatar
Josh Trembly
 
Posts: 3381
Joined: Fri Nov 02, 2007 9:25 am

Post » Fri May 27, 2011 8:10 am

Nice, I'm looking forward to trying it.
User avatar
Thomas LEON
 
Posts: 3420
Joined: Mon Nov 26, 2007 8:01 am

Post » Fri May 27, 2011 10:41 am

MW doesn't round, it truncates. At least it does normally, for e.g. set shortvar to 3.9 you get 3. I haven't tried with stats/skills specifically though.
User avatar
Klaire
 
Posts: 3405
Joined: Wed Sep 27, 2006 7:56 am

Post » Fri May 27, 2011 11:07 am

Good to know. I'll have to test my leveling script thoroughly, but I think it's going to work just fine. :)
User avatar
Dominic Vaughan
 
Posts: 3531
Joined: Mon May 14, 2007 1:47 pm

Post » Fri May 27, 2011 7:31 pm

Yeah, for levelling it should be fine (the game discards the float part for the player on reloads anyway I believe, so no big deal for companions either). Just, y'know, being pedantic and all :P
User avatar
Veronica Martinez
 
Posts: 3498
Joined: Tue Jun 20, 2006 9:43 am


Return to III - Morrowind