Jump to content

Help with script optimisaion please?


theimmersion

Recommended Posts

Well yea, you can access properties of any script I haven't actually scripted for FO so I am not sure I can really draw comparisons with that... hm...

 

I guess the best way to describe it is... It is the similar to way you've already been calling functions. Say I have a Quest and on that Quest I have a ReferenceAlias which is filled with the players reference, I want the alias to be able to access a float property called JumpValue on a Script that is attached to the Quest, lets call that TestQuestScript and on the ReferenceAlias I have a script called TestQuestPlayerAliasScript I could grab a reference of the quest and access the property through the following means:

Scriptname TestQuestScript extends Quest
	
	Float Property JumpValue Auto
	
	Event OnInit()
		JumpValue = 20
	EndEvent
	

Which of course would be the script attached to the Quest, which just sets it's property to 20 when OnInit is called.

Scriptname TestQuestPlayerAliasScript extends ReferenceAlias

	TestQuestScript Property TestQuest Auto

	Event OnInit()
		TestQuest = self.GetOwningQuest() as TestQuestScript
	EndEvent
	
	Event OnRaceSwitchComplete()
		Game.SetGameSettingFloat("fJumpFallHeightMin", 300 + TestQuest.JumpValue)
	EndEvent

This script is attached to the players alias, when OnInit happens it grabs a reference of the TestQuest as a quest using the GetOwningQuest function of Reference Alias. It then Casts the quest as TestQuestScript, if the quest didn't have the TestQuestScript attached this would return none but since it does, it will return the scripts reference. Then when the player's race changes we just set the game setting 'fJumpFallHeightMin' to 300 plus the TestQuest Property.

 

 

And that's a crash course in property access there's plenty of info around on how it works like here... well maybe not that much but it does cover it sorta.

Edited by Arocide
Link to comment
Share on other sites

So, essentially i just have to add property to the variables and they can be accessed from different Scripts.
I could even set the base script to update at 5 while the one that there to apply changes will update at 0.5 as usual.
The alias is only used to tell the quest script event happened that the quest script itself cant get.
Like load game and race change. Alias script will just tell the base quest script that it happened and not actually apply any changes.
The base script will do everything regarding what the value is and the second quest script will apply the values.
Heres what im thinking id need.


AliasScript

GlobalVariable Property GameLoaded Auto
GlobalVariable Property RaceChanged Auto

Event OnPlayerLoadGame() ;Tells my base script to run maintenance.
GameLoaded.SetValue(1)
EndEvent

Event OnRaceSwitchComplete() ;Tells my base script to recheck what race and set new values to be used.
RaceChanged.SetValue(1)
EndEvent

BaseScript

GlobalVariable Property GameLoaded Auto
GlobalVariable Property RaceChanged Auto
Float property fValueFast

Float property fValueSlow

Event OnUpdate()
if GameLoaded.GetValue() == 1
RevertNonPersistantChanges()
RaceCheck() ;SafeGuard on load
endif
if RaceChanged.GetValue() == 1 ;if race changed in the middle of session.
RaceCheck()
endif

;things that constantly need checking for changes. But dont need fast execution.
fValueFast = fValueFast + carryweightpercent / 2

fValueSlow = fValueSlow + carryweightpercent / 3

RegisterForSingleUpdate(5)
EndEvent

Function RaceCheck()
if Race == "argonianRace"
fValueFast = 30 ;base speed that differ by race.

fValueSlow = 20
elseif Race == "nordRace"
fValueFast = 20
fValueSlow = 10
endif

 

RaceChanged.SetValue(0)
EndFunction

FastScript

Event OnUpdate()

;this is the important part, it needs to check if player is running and apply the new value calculated by the base script as fast as possible.

;even if the base script calculation didnt recalculate and reapplied the new value.

;Player will less notice that change than when (like my current script) the script is slow and it applies at some seconds

;after the running making the change evidently from 100 to 130 than if the former calculation already made was 120

;and than catched up and set to 130.
if playerIsRunning
ForceAV("SpeedMult", fValueSlow)
elseif playerIsSprinting
ForceAV("SpeedMult", fValueFast)

else

ForceAV("SpeedMult", fValueDefault)

endif

RegisterForSingleUpdate(0.5)
EndEvent

 

 

This is how FO looked like.

 

 

ScriptA

float fValueA

Begin GameMode

if Waling

set fValueA to 100

endif

I can do what ever i want with it from ScriptB like it was the actual ScriptA. Literally.

End

 

ScriptB

Begin GameMode

if Running

set ScritA.fValueA to 150

;no need to even declare or any other pointers. engine just knew that it was now using fValueA like it was the ScriptA itself.

endif

End

The sweat thing is you can use any variable at any time as long as you use the scripts editor ID as prefix.

float, Integer, short, long, string. No need for globals at all.

Because you had access to them at any give time when needed in any form and use in any way any script.

 

Now in FO, i can change the value of ScriptA from within ScriptB. Thats what i loved.

No need for declarations or anything to prep. It was literally like that. And i miss this so much, id rather write than click on stuff like properties and such. -.-

 

 

 

Does the actual variable character length make a difference in performance?

Figured out i hope. Looks like its gonna hurt more the coder than it will the performance. xD

Edited by theimmersion
Link to comment
Share on other sites

Is there a way to compare IsRunning() and IsSprinting() etc?

 

This doenst compare and thus,doesnt work.

if PlayerRef.IsRunning() == True

elseif PlayerRef.IsRunning() == False

endif

 

Instead i used a work around like this.

If PlayerRef.IsRunning()

PlayerIsRunning = 1

else

PlayerIsRunning = 0

endif

 

Want to remove those many if statements. Cuz thers a lot like this.

Link to comment
Share on other sites

Theres a lot of code that checks if im running,sneaking,moving,swimming separate and at same time as well.

Take a look at the code in the first post and you can perhaps get a better idea, dont know how to actually explain other than start to write the code down. xD

 

Its under *STATES , *RAMP and *ACTIVE MODIFIERS. Unless its ok as it is or it cant be compared directly. Im in the process of eliminating any ifs and such calls i can and writing the code as small as possible. For optimization.

Edited by theimmersion
Link to comment
Share on other sites

  • Recently Browsing   0 members

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