Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

General script-writing advice


DeadHerring
 Share

Recommended Posts

I've begun writing a script that adds some OBGE screen effects to vanilla quests. I know OBSE topics aren't covered here, but that's not the focus of the advice I'm looking for anyway. I've put together a skeleton of the script to manage some special effects for the dream sequence portion of the Bravil "Through a Nightmare, Darkly" quest. No OBSE/OBGE specific code is included. This quest script just controls when the effects are turned on and off. Pretty basic. I wouldn't mind some input though, since I'm trying to come up with some conventions that will help me keep my script-writing clean and consistent, and hopefully avoid a few pitfalls as a bonus. I'd appreciate any comments on style, approach, or general script hygiene you care to share.

ScriptName OBGEScreenEffectsMS05Script


; Convenience constants

short FALSE	= 0

short TRUE	= 1


; Processing control flags

short bDelayTweaksOn		= FALSE

short bRelaxTweaks		= FALSE

short bKillEffectsProcessing	= FALSE


float fQuestDelayTime


Begin GameMode


;===================================================================================

; Script processing controllers - tweaks script execution delays for better frame sync when close to

; dream-state transitions. Tweaks are relaxed between transitions (when not close to final transition) to

; lighten CPU overhead. Processing is halted here after final transition.

;===================================================================================


If (GetStage MS05 > 10 && bDelayTweaksOn == FALSE)

	Set fQuestDelayTime to 1

	Set bDelayTweaksOn to TRUE

EndIf


If (bRelaxTweaks == TRUE)

	Set fQuestDelayTime to 1

	Set bRelaxTweaks to FALSE

EndIf


If (GetStage MS05 == 40 || GetStage MS05 == 75)

	Set fQuestDelayTime to 0.01

EndIf


If (bKillEffectsProcessing == TRUE)

	StopQuest MS05ScreenEffects

	Return

EndIf


;=============================

; Dream sequence effects controllers

;=============================


; Detect player entered in-dream quest stages and start effects

If (GetStage MS05 == 50)

	; Start dream sequence effects


	; Relax script processing

	Set bRelaxTweaks to TRUE

EndIf


; Detect player left in-dream quest stages and stop effects

If (GetStage MS05 >= 80)

	; Stop dream sequence effects


	Set bKillEffectsProcessing to TRUE

EndIf


End

Things to note:



  • Since I'm indirectly modifying a vanilla quest, I decided to make a separate quest and quest script to monitor progress through the target quest instead of modifying the original or adding activator objects to cells. From what I've read, quests aren't the most efficient way to run a script, but as far as I can see it's the closest thing to a global script that Oblivion has. And it should help avoid compatibility issues with other mods that might alter either Bravil interiors or quests. Blood & Mud comes to mind, but I haven't checked it. Thoughts? Counter-points?
  • I've added convenience constants for clarity. I haven't tested to see if C-style declaration/initialization combos work in TES scripting yet. They compile, but the script engine may ignore everything after the variable declaration for all I know. A pointer there would be nice, but I'll find out sooner or later. If it does work, what do you think of the convention?

My first script, so be nice :P Thanks in advance!

Edited by DeadHerring
Link to comment
Share on other sites

Thanks HeyYou, appreciate the feedback. :)

I have another question. When I wrote the script, I was assuming that breaking the code up into small if/then blocks would let the script run more efficiently than having larger if/then/elseif blocks since it's an interpreted language and in a game like Oblivion memory consumption is a concern, so I'd want to keep the logic structures smaller. In contrast, if this was a compiled language, I would probably expect the compiler to optimize if/then/elseif blocks to be more efficient than isolated if/then blocks at the assembly level. Does breaking things up like I've done get me any efficiency boosts? Or does it not really matter that much in this case?

In general, are there any ways to go about writing more efficient scripts?

Hopefully I'm not over-thinking this. I'm coming from a programming language where even the little things can have consequences. I know this is scripting, not programming, but I still have to wonder what goes on under the hood.

** On the same note, how much benefit am I really gaining from tweaking fQuestDelayTime?

Edited by DeadHerring
Link to comment
Share on other sites

You are indeed overthinking. :D

Scripts don't really have that much of an affect on game performance, until you get to a truly huge number. Once you get to that tipping point though, things go downhill quickly. A few members on the official forums ran some tests, and their data supports that theory.

So long as you keep your scripts flowing as smoothly as you can, without repeated/redundant code, you will be fine.

Fquestdelay time won't have that much of an impact. If you do nothing, I think they run once every five seconds. If you need it to run more often than that, set the variable accordingly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...