Jump to content

[LE] Can i make these lines into an array? If so, how? (trying to compact my script)


Recommended Posts

These are some lines in my script:

 

 

;---Variables (not a complete list)---
Float MoralityMeter		; as a max value of MoralityIncrements
Float MoralityChance1		; 5% loose control chance
Float MoralityChance2		; 10% loose control chance
Float MoralityChance3		; 15% loose control chance
Float MoralityChance4		; 20% loose control chance
Float MoralityChance5		; 25% loose control chance
Float MoralityChance6		; 30% loose control chance
Float MoralityChance7		; 35% loose control chance
Float MoralityChance8		; 40% loose control chance
Float MoralityChance9		; 45% loose control chance
Float MoralityChance10		; 50% loose control chance
Float MoralityChance11		; 55% loose control chance
Float MoralityChance12		; 60% loose control chance
Float MoralityChance13		; 65% loose control chance
Float MoralityChance14		; 70% loose control chance
Float MoralityChance15		; 75% loose control chance
Float MoralityChance16		; 80% loose control chance
Float MoralityChance17		; 85% loose control chance
Float MoralityChance18		; 90% loose control chance
Float MoralityChance19		; 95% loose control chance
Float MoralityChance20		; 100% loose control chance
Float MoralityIncrements ; contains points accumulated from all used game statistics 

;---Codes under a function (not a complete list)---
Function Loose_Control_Roll()

        MoralityChance1 = 0.05 * MoralityMeter
	MoralityChance2 = 0.10 * MoralityMeter
	MoralityChance3 = 0.15 * MoralityMeter
	MoralityChance4 = 0.20 * MoralityMeter
	MoralityChance5 = 0.25 * MoralityMeter
	MoralityChance6 = 0.30 * MoralityMeter
	MoralityChance7 = 0.35 * MoralityMeter
	MoralityChance8 = 0.40 * MoralityMeter
	MoralityChance9 = 0.45 * MoralityMeter
	MoralityChance10 = 0.50 * MoralityMeter
	MoralityChance11 = 0.55 * MoralityMeter
	MoralityChance12 = 0.60 * MoralityMeter
	MoralityChance13 = 0.65 * MoralityMeter
	MoralityChance14 = 0.70 * MoralityMeter
	MoralityChance15 = 0.75 * MoralityMeter
	MoralityChance16 = 0.80 * MoralityMeter
	MoralityChance17 = 0.85 * MoralityMeter
	MoralityChance18 = 0.90 * MoralityMeter
	MoralityChance19 = 0.95 * MoralityMeter
	MoralityChance20 = 1.00 * MoralityMeter

;other codes under Loose_Control_Roll() function
EndFunction

 

 

 

I'm trying to simplify it to make my script more compact and better looking. I'm still new to Papyrus and i heard about arrays recently, so i tried to learn about it but couldn't manage to solve my case here yet. What i'm actually trying to do is making MoralityChance to be more accurate by giving it a base value of 0.01 (or 1%) instead of 0.05 (or 5%) as stated in above lines. I heard about arrays so i thought i might use it, not only to simplify these lines but also making MoralityChance more accurate by giving it 0.01 (1%) base value and incremented until 1.00 (100%) value.

So, can we simplify these lines in my script? If so, would anyone give me a guide on how to?

Link to comment
Share on other sites

Okay, not knowing everything you are trying to accomplish this cannot be flushed out for your needs. But hopefully it can serve as an example that you can adapt to your needs.

 

 

Float MoralityMeter
Float MoralityIncrements
Float[] MoralityChance
Float Property PercentStep = 0.01 Auto ; default 1% change as desired via property settings, this is the amount by which to increase each entry.

Event OnInit()
	MoralityArrayBuilder()
EndEvent

Function MoralityArrayBuilder()
	MoralityChance = new Float[100] ;change the '100' to however many entries needed for PercentStep to go from 0.00 to 1.00 - must be a fixed number, cannot be a variable and cannot exceed 128
	Int index = 0
	While index < MoralityChance.Length
		;NOTE - first index entry needs to be 0 to fill but needs to be 1 for the math thus this
		MoralityChance[index] = ( (PercentStep * (index + 1) ) * MoralityMeter)
		index += 1
	EndWhile
EndFunction

Function Loose_Control_Roll()
	;assume a random morality chance for example usage
	Int SomeVar = RandomInt(0,100) ;adjust values to be the index range of your array entries
	Float MoralityChanceToUse = MoralityChance[SomeVar]  ;just an example on how to retrieve something stored in an array.
EndFunction

 

 

Edited by IsharaMeradin
Link to comment
Share on other sites

Okay, not knowing everything you are trying to accomplish this cannot be flushed out for your needs. But hopefully it can serve as an example that you can adapt to your needs.

 

 

Float MoralityMeter
Float MoralityIncrements
Float[] MoralityChance
Float Property PercentStep = 0.01 Auto ; default 1% change as desired via property settings, this is the amount by which to increase each entry.

Event OnInit()
	MoralityArrayBuilder()
EndEvent

Function MoralityArrayBuilder()
	MoralityChance = new Float[100] ;change the '100' to however many entries needed for PercentStep to go from 0.00 to 1.00 - must be a fixed number, cannot be a variable and cannot exceed 128
	Int index = 0
	While index < MoralityChance.Length
		;NOTE - first index entry needs to be 0 to fill but needs to be 1 for the math thus this
		MoralityChance[index] = ( (PercentStep * (index + 1) ) * MoralityMeter)
		index += 1
	EndWhile
EndFunction

Function Loose_Control_Roll()
	;assume a random morality chance for example usage
	Int SomeVar = RandomInt(0,100) ;adjust values to be the index range of your array entries
	Float MoralityChanceToUse = MoralityChance[SomeVar]  ;just an example on how to retrieve something stored in an array.
EndFunction

 

 

Many thanks! :laugh:

This should do most of the works. I'll collaborate it and i may ask again if i get another question. Once again, thanks :smile:

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...