The Black Wyrm's Lair - Forums

Mod development resources & discussion => Modder's Workshop => Topic started by: Baronius on July 07, 2005, 10:06:59 PM

Title: Maximum length for Globals
Post by: Baronius on July 07, 2005, 10:06:59 PM
I wasn't sure if this was known or not, but since it isn't in current IESDP, I thought I'd mention that in BG1: TotSC, the names of your Globals shouldn't be longer than 32 bytes.
The script will still be compiled (and can be properly decompiled), but the game will ignore the trigger/action that uses the global.

The following script block uses a global which name is exactly 32 characters long. The creatures appear in the game normally.

IF
Global("BW05_TGC1","GLOBAL",7)
Global("BW05_CreatureSummonedinMagicTrap","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("BW05_CreatureSummonedinMagicTrap","GLOBAL",1)
CreateCreature("BW05MOLD",[510.349],0)
CreateCreature("BW05HERT",[412.456],3)
END


In this block the variable's name is longer than 32 characters. The creatures start to appear in the game in an infinite loop.

IF
Global("BW05_TGC1","GLOBAL",7)
Global("BW05_CreaturesSummonedinMagicTrap","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("BW05_CreaturesSummonedinMagicTrap","GLOBAL",1)
CreateCreature("BW05MOLD",[510.349],0)
CreateCreature("BW05HERT",[412.456],3)
END

This was with 33 characters, and my tests proved that the same happens with more characters as well.

Normally it's pointless to use so long variable names, but I think it is important to know that there is such limit.

As I've said, I'm not sure if this has been already known or not.
Additionally, I am wondering if the same variable length limit applies for BG2 / other IE games...
Title: Maximum length for Globals
Post by: Rabain on July 07, 2005, 10:29:30 PM
QuoteThe script will still be compiled (and can be properly decompiled), but the game will ignore the trigger/action that uses the global.
...

The creatures start to appear in the game in an infinite loop.
According to what you are saying the game does not ignore the action but will ignore the setting of the global variable.

If the creatures appear in the game but will not stop spawning it means the script action has run but is still True...ergo the global was not incremented.

yes?
Title: Maximum length for Globals
Post by: devSin on July 07, 2005, 10:30:35 PM
It's noted in the format descriptions for ARE and GAM (and possibly EFF, since LOCALS are all internal EFF data to the creature object). The fields to store the variable name are all 32 bytes in length. I don't know if anybody has checked the behavior to see if it's just truncated on set (only the first 32 characters will be written), or if it doesn't get set at all, though.
Title: Maximum length for Globals
Post by: The Bigg on July 07, 2005, 10:33:39 PM
If you check the IESDP, you'll see that the baldur.gam structure has finite bytes for a variable name (32 for global and area, 24 for locals). Hence, the second script was incrementing tha variable BW05_CreaturesSummonedinMagicTra and checking for BW05_CreaturesSummonedinMagicTrap, hence the loop.
Title: Maximum length for Globals
Post by: Baronius on July 07, 2005, 10:41:03 PM
QuoteAccording to what you are saying the game does not ignore the action but will ignore the setting of the global variable.
Right, I was incorrect in my statement. (I actually meant that the action didn't work properly.)

QuoteIf you check the IESDP, you'll see that the baldur.gam structure has finite bytes for a variable name (32 for global and area, 24 for locals). Hence, the second script was incrementing tha variable BW05_CreaturesSummonedinMagicTra and checking for BW05_CreaturesSummonedinMagicTrap, hence the loop.
Checking the structure of baldur.gam would have been a good idea.  Anyway, I think that in the next version of IESDP these length limits could be mentioned in the Variables section.
Title: Maximum length for Globals
Post by: Rabain on July 07, 2005, 10:45:15 PM
Why does only one global get truncated?

If both are over 32 should they both not get truncated or does the trigger portion ignore the length?

Does that make sense?
Title: Maximum length for Globals
Post by: The Bigg on July 07, 2005, 11:25:15 PM
Quote from: RabainWhy does only one global get truncated?

If both are over 32 should they both not get truncated or does the trigger portion ignore the length?

Does that make sense?
the global name is stored in a 32 byte space, so only 32 characters in memory (the SetGlobal part).
However, I'd wager that the devs at bioware used the strcmp functions to scan the variable listing (searching the entries in baldur.gam until you find one equal to the one you're searching for).
So, when parsing the script you'll never find a value for BW05_CreaturesSummonedinMagicTrap, since the only variable which was set is BW05_CreaturesSummonedinMagicTra.

Of course, we might have Weimer limit the lenght of the variable names to 32 bytes to hide similar problems  ;)
Title: Maximum length for Globals
Post by: Rabain on July 08, 2005, 07:38:37 AM
Yeah I thought about the weidu thing last night too.  

That could be a helpful Feature for those who likereallylongvariablenames. :)
Title: Maximum length for Globals
Post by: The Bigg on July 08, 2005, 09:35:38 AM
Actually not, since one could use the variables
1234567890123456789012345678901234567890 (40 chars) and 123456789012345678901234567890123456789 (39 chars)

and the game will think they are the same.

Much better if WeiDU chocked (or gave warnings) about these things.
Title: Maximum length for Globals
Post by: Rabain on July 08, 2005, 11:33:08 AM
That's what I meant:  if weidu didn't accept long variable names the modder would be forced to work in the correct way 32 bytes or less.

If the length is limited in weidu to 32 bytes it could provide a warning/error as to why!

Maybe my post wasn't particularly clear...sorry.

:)
Title: Maximum length for Globals
Post by: igi on July 08, 2005, 11:34:01 AM
I do know this, and, as has been noted, it is in the IESDP.

It may not be in the right place in the IESDP, but .. thats.. umm.. to encourage people to read the entire thing.
Obviously :)

There's also a limit as to how high you can set variables, which I don't think is listed in the IESDP though.
Title: Maximum length for Globals
Post by: The Bigg on July 08, 2005, 12:06:42 PM
Quote from: igiI do know this, and, as has been noted, it is in the IESDP.

It may not be in the right place in the IESDP, but .. thats.. umm.. to encourage people to read the entire thing.
Obviously :)

There's also a limit as to how high you can set variables, which I don't think is listed in the IESDP though.
Lemme guess... 4 signed bytes?  ;)
Title: Maximum length for Globals
Post by: igi on July 08, 2005, 12:10:32 PM
QuoteLemme guess... 4 signed bytes?

Well, actually, I'm not sure.
I think I recall a conversation with Avenger, where he stated the maximum value was lower than this. I also think I remember my testing showing a maximum value significantly higher than this (and when the max limit was passed, there value was not set to the max, or wrapped around, it just entered a pattern I don't remember).

Testing would be welcome. 4 signed bytes would be a good place to start :)
Title: Maximum length for Globals
Post by: Baronius on July 08, 2005, 03:19:55 PM
QuoteIt may not be in the right place in the IESDP, but .. thats.. umm.. to encourage people to read the entire thing.
Obviously :)
This means that you will mention the size limits in the Variable section too in the next release, right? :P
Remember, IESDP is for (starter) modders as well, and not for programmers.
Title: Maximum length for Globals
Post by: devSin on July 08, 2005, 04:10:10 PM
QuoteI think I recall a conversation with Avenger, where he stated the maximum value was lower than this. I also think I remember my testing showing a maximum value significantly higher than this (and when the max limit was passed, there value was not set to the max, or wrapped around, it just entered a pattern I don't remember).
That's a tricky question, since most compilers won't let you get away with values larger than 2^32. Since the variable value is signed, it should give a range from -2^31 to 2^31 - 1 (if that's indeed the maximum size). Conveniently, this range also applies to STATEs and whatnot.

If the size can be larger, it wouldn't really make much difference as the current compilers will do funky things once you get too large (IIRC, NI will use the unsigned value, and WeiDU will fail).
Title: Maximum length for Globals
Post by: Avenger_teambg on July 23, 2005, 07:02:42 PM
Variables (globals/locals) are signed dwords (4 bytes)
Some stats are unsigned.