Streamlining a script with Player.RemoveSpell

Post » Sat May 28, 2011 6:58 pm

This probably sounds like a silly question to some, but like many here I'm mostly self-taught on FO3 scripting by pulling things apart. In any case...

Is there a performance and/or potential problem in doing...

If (Player.IsSpellTarget ExampleSpell == 1)     Player.RemoveSpell ExampleSpellEndIf


...vs simply...

Player.RemoveSpell ExampleSpell


In other words, is it better to check if the effect is active before trying to remove it, or does it matter? Does it cause a problem if you try to remove it and it isn't there? Is there a performance hit or improvement one way or the other? (In my current case, I have a single long script that includes a couple dozen examples of the above)
User avatar
Damned_Queen
 
Posts: 3425
Joined: Fri Apr 20, 2007 5:18 pm

Post » Sat May 28, 2011 6:09 am

I dont see anything wrong with either way. Perforcmance hits only usually occur when a script is doing like 10 things every single frame no matter what. What you have set up will make it only hit performance more if they do have the effect. With example one, if they dont have it, it runs 1 line of code, if they do, 2. Bottom, runs 1 no matter what. 1 extra line of code will not affect performance on computer made after like... 1992 maybe, if even. So either way will be fine. Is it running every single frame in a gamemode block? Or only when a certain thing occurs?
User avatar
Stephanie I
 
Posts: 3357
Joined: Thu Apr 05, 2007 3:28 pm

Post » Sat May 28, 2011 7:59 pm

Right now, all 24 instances of that example are running freely in a gamemode block.

I have been thinking however of moving that within a more global If statement, considering -most- (not all, which is why I'd need to play with it) of the things that this would need to respond to are already based on

If ((GameDaysPassed - PreviousValueOfGameDaysPassed) >= 0.04)



...based on your comments, I take it that making this sort of a change would have a noticable performance impact?
User avatar
Multi Multi
 
Posts: 3382
Joined: Mon Sep 18, 2006 4:07 pm

Post » Sat May 28, 2011 12:03 pm

Just a note, if you're comparing something where the only important thing is "Is it 0 or non-0" you can use "if thing", which acts as "if thing != 0" but is slightly more efficient.
User avatar
Justin Hankins
 
Posts: 3348
Joined: Fri Oct 26, 2007 12:36 pm

Post » Sat May 28, 2011 8:54 am

Right -- something I just learned in the mods forum earlier today (and just haven't had the chance to go back and reflect that all through the few hundred lines of scripts I currently have "up in the air").
User avatar
Hayley Bristow
 
Posts: 3467
Joined: Tue Oct 31, 2006 12:24 am

Post » Sat May 28, 2011 11:19 am

Right now, all 24 instances of that example are running freely in a gamemode block.


Oh, I misspoke -- there are 24 instances of the removespell example I gave, but they are split up into 6 groups of 4 -- and each group is surrounded by an "if (shortvar < 0)"

...so they would only be getting run if the particular short associated with that group had dropped below 0, which in normal gameplay shouldn't occur too often.
User avatar
Charles Mckinna
 
Posts: 3511
Joined: Mon Nov 12, 2007 6:51 am

Post » Sat May 28, 2011 12:28 pm

I've released a utility that you can use to test the efficiency of different sequences of code, which you could use to easily test the difference in efficiency of these two methods - http://www.fallout3nexus.com/downloads/file.php?id=11239

Cipscis
User avatar
Brooks Hardison
 
Posts: 3410
Joined: Fri Sep 07, 2007 3:14 am


Return to Fallout 3