The Black Wyrm Lair Forums
The Black Wyrm's Lair Terms of Use Help Search Members Calendar

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Maximum length for Globals, 32 characters
Baronius
post Jul 7 2005, 10:06 PM
Post #1


Master of energies
Group Icon

Council Member
Posts: 3307
Joined: 9-July 04
From: Magyarország




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.
CODE

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.
CODE

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...


--------------------
Mental harmony dispels the darkness.
Go to the top of the page
 
Quote Post
Rabain
post Jul 7 2005, 10:29 PM
Post #2


GOD


Retired team member
Posts: 1728
Joined: 14-July 04
From: Ireland




QUOTE
The 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?
Go to the top of the page
 
Quote Post
devSin
post Jul 7 2005, 10:30 PM
Post #3





Forum Member
Posts: 53
Joined: 22-March 05




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.

This post has been edited by devSin: Jul 7 2005, 10:33 PM
Go to the top of the page
 
Quote Post
The Bigg
post Jul 7 2005, 10:33 PM
Post #4





Forum Member
Posts: 165
Joined: 29-January 05
From: Modena (Italy)




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.


--------------------
Please do not contact me for assistance in using BGT, BP, any other of the 'large mods', or a mod I didn't write or contribute to. I'm not your paid support staff, so I'd suggest you to direct your help questions to the forum relative to the mod you're playing.

Thanks for your cooperation.
Go to the top of the page
 
Quote Post
Baronius
post Jul 7 2005, 10:41 PM
Post #5


Master of energies
Group Icon

Council Member
Posts: 3307
Joined: 9-July 04
From: Magyarország




QUOTE
According 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.)

QUOTE
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.

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.


--------------------
Mental harmony dispels the darkness.
Go to the top of the page
 
Quote Post
Rabain
post Jul 7 2005, 10:45 PM
Post #6


GOD


Retired team member
Posts: 1728
Joined: 14-July 04
From: Ireland




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?
Go to the top of the page
 
Quote Post
The Bigg
post Jul 7 2005, 11:25 PM
Post #7





Forum Member
Posts: 165
Joined: 29-January 05
From: Modena (Italy)




QUOTE(Rabain @ Jul 7 2005, 10:45 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?

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 wink.gif


--------------------
Please do not contact me for assistance in using BGT, BP, any other of the 'large mods', or a mod I didn't write or contribute to. I'm not your paid support staff, so I'd suggest you to direct your help questions to the forum relative to the mod you're playing.

Thanks for your cooperation.
Go to the top of the page
 
Quote Post
Rabain
post Jul 8 2005, 07:38 AM
Post #8


GOD


Retired team member
Posts: 1728
Joined: 14-July 04
From: Ireland




Yeah I thought about the weidu thing last night too.

That could be a helpful Feature for those who likereallylongvariablenames. smile.gif
Go to the top of the page
 
Quote Post
The Bigg
post Jul 8 2005, 09:35 AM
Post #9





Forum Member
Posts: 165
Joined: 29-January 05
From: Modena (Italy)




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.


--------------------
Please do not contact me for assistance in using BGT, BP, any other of the 'large mods', or a mod I didn't write or contribute to. I'm not your paid support staff, so I'd suggest you to direct your help questions to the forum relative to the mod you're playing.

Thanks for your cooperation.
Go to the top of the page
 
Quote Post
Rabain
post Jul 8 2005, 11:33 AM
Post #10


GOD


Retired team member
Posts: 1728
Joined: 14-July 04
From: Ireland




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.

smile.gif
Go to the top of the page
 
Quote Post
igi
post Jul 8 2005, 11:34 AM
Post #11


IESDP Guardian


Forum Member
Posts: 175
Joined: 22-July 04




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 smile.gif

There's also a limit as to how high you can set variables, which I don't think is listed in the IESDP though.


--------------------
Go to the top of the page
 
Quote Post
The Bigg
post Jul 8 2005, 12:06 PM
Post #12





Forum Member
Posts: 165
Joined: 29-January 05
From: Modena (Italy)




QUOTE(igi @ Jul 8 2005, 11:34 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 smile.gif

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? wink.gif


--------------------
Please do not contact me for assistance in using BGT, BP, any other of the 'large mods', or a mod I didn't write or contribute to. I'm not your paid support staff, so I'd suggest you to direct your help questions to the forum relative to the mod you're playing.

Thanks for your cooperation.
Go to the top of the page
 
Quote Post
igi
post Jul 8 2005, 12:10 PM
Post #13


IESDP Guardian


Forum Member
Posts: 175
Joined: 22-July 04




QUOTE
Lemme 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 smile.gif


--------------------
Go to the top of the page
 
Quote Post
Baronius
post Jul 8 2005, 03:19 PM
Post #14


Master of energies
Group Icon

Council Member
Posts: 3307
Joined: 9-July 04
From: Magyarország




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

This means that you will mention the size limits in the Variable section too in the next release, right? tongue.gif
Remember, IESDP is for (starter) modders as well, and not for programmers.


--------------------
Mental harmony dispels the darkness.
Go to the top of the page
 
Quote Post
devSin
post Jul 8 2005, 04:10 PM
Post #15





Forum Member
Posts: 53
Joined: 22-March 05




QUOTE
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).

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).

This post has been edited by devSin: Jul 8 2005, 04:11 PM
Go to the top of the page
 
Quote Post
Avenger_teambg
post Jul 23 2005, 07:02 PM
Post #16





Forum Member
Posts: 78
Joined: 13-July 05




Variables (globals/locals) are signed dwords (4 bytes)
Some stats are unsigned.


--------------------
See GemRB !
Go to the top of the page
 
Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:



- Lo-Fi Version Time is now: 19th May 2024 - 05:04 AM