Jump to content


Photo

Scripting practrices


10 replies to this topic

#1 aiqa

aiqa
  • Member
  • 21 posts

Posted 07 October 2017 - 07:12 AM

In my previous (strongly modded) game I ended up with getting quite a bit of stutter. And after reading up on it and looking over my mods list I noticed I had quite a few script heavy mods that would not really miss (disadvantage of using BWS presets :whistling:).

 

I reinstalled without the mods I thought would be a problem and things are working a lot better for now.

However this did get me thinking about scripting limitations and practices, and how important certain things are.

So the easy thing to first check is the baldur.bcs script, since as I understand it that continuously runs.

 

So now to SOS.

I've noticed my baldur.bcs script is about 13000 lines, and when skimming over those most seem reasonable and at least have a delay or a variable before it starts doing things with items.

SOS however looks a bit weird in that regard.

First of all, SOS adds well over 3000 lines to baldur.bcs, which seems a bit excessive.

Then it has a ton of things like:

IF
	HasItem("CBHBSLZP",Player6)
	PartyHasItemIdentified("CBHBSLZP")
	Global("CbPlayer6Has_Soul_zapper","GLOBAL",0)
	!Global("CbPlayer1Has_Soul_zapper","GLOBAL",1)
	!Global("CbPlayer2Has_Soul_zapper","GLOBAL",1)
	!Global("CbPlayer3Has_Soul_zapper","GLOBAL",1)
	!Global("CbPlayer4Has_Soul_zapper","GLOBAL",1)
	!Global("CbPlayer5Has_Soul_zapper","GLOBAL",1)
THEN
	RESPONSE #100
		SetGlobal("CbPlayer6Has_Soul_zapper","GLOBAL",1)
END

 

To me it looks like that could really do with a Delay(10) or something.

So the question to the people that are a bit more versed in BG2 scripting, is that actually something that could cause stuttering or am I completely on the wrong path?

 

Also I am now still in the early stages of BG1, and I don't really remember those items at all since it's been a while I've last played BG.

Are they even really important in SOS.


Edited by aiqa, 07 October 2017 - 07:30 AM.


#2 jastey

jastey
  • Member
  • 688 posts

Posted 07 October 2017 - 07:35 AM

What do you man by stutter? Stutter in BG mods mean usually that you have an NPC who tries to intitiate dialogue but can't for some reason so he will stop every second not moving further and not following commands. I guess you mean that our game is lagging? Script blocks as you posted could increase this as the game has to constantly check whether the condition is true, so I guess having tons of them would lead to lagging but I am not an expert.

Why would you suggest adding a Delay(10)?



#3 aiqa

aiqa
  • Member
  • 21 posts

Posted 07 October 2017 - 07:46 AM

The whole game was stopping for a fraction of a second, every seconds or so.

 

A delay(10) would at least not have the script constantly check for those items, but only every so often.

Depending on how the items are using in quests and such that could, or could not, work without many disadvantages.

 

All in all I am seeing SOS adding a "hasitem", without a global viariable check before it, 36 times in baldur.bcs.

So if I understand that function correctly, it would have to search character inventories 36 times every time the script runs.

How often does baldur.bcs actually run?


Edited by aiqa, 07 October 2017 - 07:49 AM.


#4 The Imp

The Imp

    Not good, see EVIL is better. You'll LIVE.

  • Member
  • 4168 posts

Posted 07 October 2017 - 08:17 AM

The whole game was stopping for a fraction of a second, every seconds or so.

 

A delay(10) would at least not have the script constantly check for those items, but only every so often.

WHEN you experience stutter;

Then install the LStest mod and find out which script, and part of it, the stutter causer is, uninstall the LStest mod, and eliminate the part of the script, after which you can go on to kill&maim and destroy a fantasy setting.

 

Otherwise, shut up.

 

First of all, SOS adds well over 3000 lines to baldur.bcs, which seems a bit excessive.

Doesn't matter much...

You can avoid the above stutter by not having two CBHBSLZP.itm's in your party's inventory.


Edited by The Imp, 07 October 2017 - 08:28 AM.

Yep, Jarno Mikkola. my Mega Mod FAQ. Use of the BWS, and how to use it(scroll down that post a bit). 
OK, desert dweller, welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand. Ouh, actually it was still snow then.. but anyways.


#5 aiqa

aiqa
  • Member
  • 21 posts

Posted 07 October 2017 - 08:22 AM

So I've looked at the SOS walkthrough:

 

There are quite a few Hellblades around this dungeon and they all act like +3 swords, although have extra enchantments attached to them. They are notionally sentient and form a strong bond with their owner, and apparently cause the wielder to gradually become Chaotic Evil and start doing dastardly deeds. To be honest I didn’t bother with them, since all of my party had better weapons, but I’d be interested to hear from anyone who has used them and rates them.

 

So then those items seem to be mostly flavor.

And for 5 flavor items (that I probably wont even use) adding well over 3000 lines (or 30%) to baldur.bcs really seems a bit excessive.

So I'll just be deleting those lines, and I'll live with these 6 items not bonding or changing alignments.

 

The whole game was stopping for a fraction of a second, every seconds or so.

 

A delay(10) would at least not have the script constantly check for those items, but only every so often.

Then install the LStest mod and find out which script, and part of it, the stutter causer is, uninstall the mod, and eliminate the part and go on to kill&maim and destroy a fantasy setting.

 

To late for that now I've already restarted, but thank you for the advice. If I get to have more stuttering problems I'll be sure to make use of that.



#6 aiqa

aiqa
  • Member
  • 21 posts

Posted 07 October 2017 - 09:21 AM

You can avoid the above stutter by not having two CBHBSLZP.itm's in your party's inventory.

 

I assume like all other scripting languages it just run from top to bottom.

And since the first line there is HasItem("CBHBSLZP",Player6), it will always start with doing an inventory check.

It does 36 of those every second, or how ever often the script repeats.

And if you also have a few bags in your inventory, I assume it will also check those.

I am not an expert on BG scripts, but to me that all looks less than optimal, and could potentially put a bit of a strain on things.

 

I could be wrong of course, but if so please explain why?

Is checking inventories hugely fast in BG?



#7 Roxanne

Roxanne

    Modder

  • Member
  • 2747 posts

Posted 07 October 2017 - 09:58 AM

In the readme you quote

There are quite a few Hellblades around this dungeon

 

It is very long ago that I played the mod but I remember that you find those items in just one place. You can only leave this place through another area. If such a check has to be made, it does not belong to Baldur.bcs but to the area script of that second area, There you check once and set the globals. You never need to check that before or after.

The best example for such a case is the check for drow items to crumble on the surface. You do that once in the possible entry area on the surface and you are done,

There is no need to misuse baldur.bcs to find a condition that can be clearly isolated to one or two areas. Especially in pre-EE games, item search has slowed the game significantly. (And just make it clear - the code will run in the game from beginning to end on every turn unless you decide to pick that item, which may never be the case at all.). 

 

You may very well change the thread's headline to *Bad Scripting Practice".


Edited by Roxanne, 07 October 2017 - 09:59 AM.

The Sandrah Saga

another piece of *buggy, cheesy, unbalanced junk*


#8 Roxanne

Roxanne

    Modder

  • Member
  • 2747 posts

Posted 07 October 2017 - 10:19 AM

This makes it even worse, the sequence of triggers (as they are again checked from top to bottom.)

 

Global("CbPlayer6Has_Soul_zapper","GLOBAL",0)

HasItem("CBHBSLZP",Player6)

PartyHasItemIdentified("CBHBSLZP")

Global("CbPlayer6Has_Soul_zapper","GLOBAL",0)

blabla

SetGlobal("CbPlayer6Has_Soul_zapper","GLOBAL",1)

 

Because even if the whole check is completely unnecessary because the global is already at 1, this will only be found after the whole inventory has already been searched...


Edited by Roxanne, 07 October 2017 - 10:21 AM.

The Sandrah Saga

another piece of *buggy, cheesy, unbalanced junk*


#9 aiqa

aiqa
  • Member
  • 21 posts

Posted 07 October 2017 - 10:56 AM

This is the code for 1 weapon for 1 player. This repeats for 6 players for 6 weapons (that is why there are 36 inventory checks no matter what).

 

Spoiler

 

Like you said, the "HasItem" at the top of the script block makes sure it always does the inventory search, no matter what the other variables are set to.

But once some variables do get set there are even more.

 

If you set Global("CbPlayer1Has_Life_Eater","GLOBAL",5) I am counting two extra item checks on player1, and two extra party wide checks.

So if you give all your characters one weapon, you'd get 48 single player inventory checks, and 12 party wide inventory checks.


Edited by aiqa, 07 October 2017 - 11:05 AM.


#10 Almateria

Almateria

    most garbage person

  • Member
  • 862 posts

Posted 07 October 2017 - 05:05 PM

Making the script area-only would not help as swords can be equipped at any time and not only at a single place.
Proposal: change to HasWeaponEquipped to cut the inventory check to 1/10 of its size?

#11 Roxanne

Roxanne

    Modder

  • Member
  • 2747 posts

Posted 08 October 2017 - 12:23 AM

Making the script area-only would not help as swords can be equipped at any time and not only at a single place.
Proposal: change to HasWeaponEquipped to cut the inventory check to 1/10 of its size?

This is correct. However -

The thing with the area check serves another purpose:

- you find these items in a single place only. If you pick it put and leave that area, the check sets a global.

- Only if that global is set (i.e. only if your party ever visited the place and took the item), you would ever need to do any of the multiple other checks

- the global to do subsequent checks is the first condition checked to be true in all the other blocks, otherwise they are just skipped and there is no need to even look into inventories at all.


The Sandrah Saga

another piece of *buggy, cheesy, unbalanced junk*




Reply to this topic