Jump to content

Looking for ways to optimize scripts


temnix

Recommended Posts

I have a lot of scripts on hand with numerous OR conditions, as thick as bad cholesterol in arteries after a lifetime of butter and margarine. I'd like to make them go faster, if possible. For example, does putting Player1's variable on top make the engine skip the rest of the conditions?

OR(9565)

TriggerOverride(Player1,Global("VAR","LOCALS",1))
...

Does this make it faster, as opposed to putting Player1 at the end somewhere? Anything else that can be done?

Link to comment

I'll state my interest in this question, as well. Any optimization for trigger scripts orders would be welcome. The only one I know of is thet AreaType() checks shouldn't be the one failing a dream script block or the game will crash if the NPC is dead (at least for classic game).

Any other optimum order to save time in scripts? Best to make the "NPC can talk" checks first? Or the dialogue trigger variable first? Or...?

Link to comment

IIRC ORs are slow, since every triggers is checked (thus CD_STATE_NOT_VALID exists). Checking gvars is fast.

Obviously, It's best to cut off early.

Anyway, there's not much point in thinking about it until you actually hit a performance problem.

Link to comment
7 minutes ago, qwerty1234567 said:

Obviously, It's best to cut off early.

The thing is that I have problems to determine which would lead to the earliest cut off.

The InParty check

The NPC can talk check

The actual trigger variable of this dialogue

The other triggers that determine this one special dialogue occation?

Every one is the first at some instances, but not at others.

It's a principle question for me, but I'd be curious if there is knowledge, experiences, or even prejudices in the community.

 

Link to comment
37 minutes ago, jastey said:

The thing is that I have problems to determine which would lead to the earliest cut off.

The InParty check

The NPC can talk check

The actual trigger variable of this dialogue

...

The AND checks, aka you don't ever put these in an OR() check... dan-da-daa. Yes, that's what he answered with.

Link to comment
11 hours ago, jastey said:

The InParty check

The NPC can talk check

The actual trigger variable of this dialogue

damn, I wrote a longish reply, pressed ctrl-z to cancel last words and IPB deleted it all with no possibility of restoring

Short answer: just these 3 - no difference.

Link to comment

My experience from various adventures optimizing SCS scripts (all of this is from memory and from some while ago):

- I think OR() blocks evaluate from bottom to top, stopping when they reach a valid condition; I also think they're relatively slow; avoid them if possible. 

- Checking globals is very quick. If there is a global in your check, check it first.

- Scripts are evaluated 30 times per second. If you are doing something complicated that doesn't need to be checked 30 times per second, see if you can slow it down. E.g., use a Delay(), or set a timer to reset every six seconds and put !GlobalTimerNotExpired at the start of your block.

- most importantly, don't worry about it unless you are doing something very complicated indeed. The BG2 engine evaluates scripts very fast; the BGEE engine even more so. SCS scripts are often 10,000 lines long or more, and even so I quite rarely have to worry about optimisation. In normal circumstances, don't worry about this preemptively - wait till you see actual slowdowns.

Link to comment

Bumping this topic, it's of interest to me.

On 6/28/2020 at 10:47 AM, DavidW said:

My experience from various adventures optimizing SCS scripts (all of this is from memory and from some while ago):

- I think OR() blocks evaluate from bottom to top, stopping when they reach a valid condition; I also think they're relatively slow; avoid them if possible.

I do use OR() a lot in my scripts to see when a caster should attempt True Sight, dispel etc. you're saying that it's faster to check in separate blocks whether Player1 is STATE_IMPROVEDINVISIBILITY, Player1 is STATE_MIRRORIMAGE, and so forth for each potential target?

I have noticed script related slowdowns on a map I was working on with 5 mages, 10 archers and 10 warriors. The mages when spawned together via console on a separate map didn't cause such problems, and their scripts are ~3400 lines each. Experimentally, I replaced them in my map with SCS mages of about the same level, this didn't help the slowdowns. The archers' targeting does contain a fair number of OR() conditions though.

I seem to remember the map working fine once before, but it's possible I had the archers using the old WTARSGT, which doesn't contain OR()s.

Link to comment

Join the conversation

You are posting as a guest. 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.

×
×
  • Create New...