Need a Second Pair of Eyes on a Script

Post » Tue Jan 19, 2016 8:43 am

I'm tweaking a few scripts, trying to pair down things like global variables if they're not absolutely needed and such, and need someone to take a look at the changes I've made to my inscription scripts.



Here's the old one (just the altered part):



If ( successratio >= 20 )
Set addition To Random, 3
Set increment To ( ( 100 / Inscription_skill ) + ( addition + 1 ) ) / 100
Set Inscription_skill To ( Inscription_skill + increment )
messagebox, "Increment is %.2f, Inscription_skill is %.2f", increment, Inscription_skill
Set btemp To InscriptionStored + 1
If ( btemp <= Inscription_skill ) ;if you are ready to advance one point in skill.
Set InscriptionStored To Inscription_skill
PlaySound, "skillraise"
MessageBox "Your Inscription skill has increased to %.0f", Inscription_skill
EndIf
Else ;If NOT successful
Set increment To ( ( 100 / Inscription_skill ) ) / 200
Set Inscription_skill To ( Inscription_skill + increment )
messagebox, "Increment is %.2f, Inscription_skill is %.2f", increment, Inscription_skill
Set btemp To InscriptionStored + 1
If ( btemp <= Inscription_skill )
Set InscriptionStored To Inscription_skill
PlaySound, "skillraise"
MessageBox "You have learned from your mistakes, and your Inscription skill has increased to %.0f", Inscription_skill
EndIf
EndIf

And these are my changes, using a temporary float (tempf) to replace what the global variable Inscription_Skill was being used for and using Inscription_Skill in place of the global InscriptionStored (which has been made redundant):



If ( successratio >= 20 )
Set addition To Random, 3
Set increment To ( ( 100 / Inscription_skill ) + ( addition + 1 ) ) / 100
Set tempf To ( Inscription_skill + increment )
messagebox, "Increment is %.2f, tempf is %.2f", increment, tempf
Set temps To Inscription_Skill + 1
If ( temps <= tempf ) ;if you are ready to advance one point in skill.
Set Inscription_Skill To tempf
PlaySound, "skillraise"
MessageBox "Your Inscription skill has increased to %.0f", Inscription_skill
EndIf
Else ;If NOT successful
Set increment To ( ( 100 / Inscription_skill ) ) / 200
Set tempf To ( Inscription_skill + increment )
messagebox, "Increment is %.2f, tempf is %.2f", increment, tempf
Set temps To Inscription_Skill + 1
If ( temps <= tempf )
Set Inscription_Skill To tempf
PlaySound, "skillraise"
MessageBox "You have learned from your mistakes, and your Inscription skill has increased to %.0f", Inscription_skill
EndIf
EndIf

I just thought having two global variables (both floats), which amount to the exact same number once the script has finished running, is unnecessary. Particularly when they're supposed to represent a skill like enchanting, which only ever needs one stored value.



Do my changes look all right?

User avatar
Blackdrak
 
Posts: 3451
Joined: Thu May 17, 2007 11:40 pm

Post » Tue Jan 19, 2016 6:46 am

Looks fine to me from the excerpt. So long as you're using the same variable types I doubt this would introduce any errors.

User avatar
Ria dell
 
Posts: 3430
Joined: Sun Jun 25, 2006 4:03 pm

Post » Tue Jan 19, 2016 9:46 am



Cool, thank you! Yeah, they're all floats, and that excerpt is the only bit that contains any of those variables. The temps variable is a short, but the btemp it replaced has always been one. It's meant to round down to the nearest integer for the skillraise check.
User avatar
Sebrina Johnstone
 
Posts: 3456
Joined: Sat Jun 24, 2006 12:58 pm


Return to III - Morrowind