Jump to content


Photo

Longer variable names: bad or okay?


8 replies to this topic

#1 Creepin

Creepin
  • Members
  • 154 posts
  • Gender:Male
  • Location:Moscow

Posted 16 May 2017 - 12:38 AM

I remember reading in an ancient times that the longer variable names are the more they slow down script parsing by game engine and thus slow down the game, so I have made my best ever since to stick with 8 symbols variable names even though SetGlobal("GOBLIN_QUEST_DID_DOG_SMELLED_MEDALLION","GLOBAL",1) is much more obvious and easy to track than SetGlobal("CRVAR034","GLOBAL",1). I believed it without doubt for many years but finally decided to ask around, was this idea regarding length of variable names any valid or there's no real reason to stick to shorter names?


Edited by Creepin, 16 May 2017 - 12:53 AM.


#2 argent77

argent77
  • Modders
  • 680 posts
  • Gender:Male

Posted 16 May 2017 - 01:45 AM

I don't know about slowdown effects (which would be rather insignificant compared to checks like PartyHasItem("xyz")). However, for technical reasons variable names can't be longer than 32 characters.



#3 Roxanne

Roxanne
  • Modders
  • 1498 posts
  • Gender:Not Telling

Posted 16 May 2017 - 01:59 AM

I don't know about slowdown effects (which would be rather insignificant compared to checks like PartyHasItem("xyz")). However, for technical reasons variable names can't be longer than 32 characters.

The rumour persists for a long time...even though there always existed those SetGlobal("SPRITE_IS_DEADcvfist21","global",0).which are pretty long even in old vanilla games.

 

At least in vanilla BG2EE, longer variables are used throughout, e.g. IncrementGlobal("bd_poison_dsc_supplies","global",1).

In my mods I have always used globals that were (at least for myself) meaningful enough to get an idea what they stand for - never any issues even in the very big BGT or EET installations I used that could be assigned to names of a global.

Slowdown effects always had other reasons, yes, inventory checks being the most common, followed by animation issues, not removed invisible creatures from spells and some others.


Edited by Roxanne, 16 May 2017 - 02:00 AM.

The Sandrah Saga

another piece of *buggy, cheesy, unbalanced junk*


#4 Jarno Mikkola

Jarno Mikkola

    The Imp

  • Modders
  • 6122 posts
  • Gender:Male
  • Location:The town where the dead haven't keeled over, yet. In Finland.

Posted 16 May 2017 - 02:06 AM

The rumour persists for a long time...even though there always existed those SetGlobal("SPRITE_IS_DEADcvfist21","global",0).which are pretty long even in old vanilla games.

erhm, you do understand that the characters before the ...cvfist21 is 14 characters... so there's plenty to have as the death variable... as 32-14 = 18 ... math.
Welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand.
Here's how to install all the ... mods you ever really could want to Infinity Engine games. I removed the stable word from there as Roxanne began to add BS mods that are likely to break compatibility from the BWS.

#5 Creepin

Creepin
  • Members
  • 154 posts
  • Gender:Male
  • Location:Moscow

Posted 16 May 2017 - 02:34 AM

Thank you for your prompt replies! :thumbsup:
 

I don't know about slowdown effects (which would be rather insignificant compared to checks like PartyHasItem("xyz")). However, for technical reasons variable names can't be longer than 32 characters.

Even though variable name effect (if any) can't be nearly as ruinous as PartyHasItem's carelessly crammed in baldur.bcs & co. (grrrr!), the more reasons to try to help IE to cope with all that added joy. BTW I didn't knew about 32 symbols limitation, thank you for bringing that up.
 

The rumour persists for a long time...even though there always existed those SetGlobal("SPRITE_IS_DEADcvfist21","global",0).which are pretty long even in old vanilla games.
 
At least in vanilla BG2EE, longer variables are used throughout, e.g. IncrementGlobal("bd_poison_dsc_supplies","global",1).
In my mods I have always used globals that were (at least for myself) meaningful enough to get an idea what they stand for - never any issues even in the very big BGT or EET installations I used that could be assigned to names of a global.
Slowdown effects always had other reasons, yes, inventory checks being the most common, followed by animation issues, not removed invisible creatures from spells and some others.

So you heard that rumour too, that's good, at least now I'm sure that wasn't the figment of my imagination! I thought of vanilla variables but these were honestly used with no need to consider BG being bloated up to 40Gb and having checks over checks over checks in its scripts. Thanks for the sharing field experience though - this might be the closest to full-fledged study I could have asked for, and considering the size of your mod this holds quite some credibility.
 

erhm, you do understand that the characters before the ...cvfist21 is 14 characters... so there's plenty to have as the death variable... as 32-14 = 18 ... math.

Jarno, the point was not whether DV will fit into the rest of 32 symbols or not but whether it's ok to use variable names longer than 8 symbols, and at that I believe SPRITE_IS_DEADcvfist21 served as a good example by being x2,5 longer.


Edited by Creepin, 16 May 2017 - 03:28 AM.


#6 Ardanis

Ardanis

    A very GAR character

  • Modders
  • 2545 posts
  • Gender:Male
  • Location:Saint-Petersburg, Russia

Posted 16 May 2017 - 02:54 PM

SPRITE_IS_DEADscritpname global is automatically set each time a creature with scriptname dies and can be later checked with Dead("scriptname") shorthand. So no, it's not an example of SetGlobal("very_long_var_name_here","global",1) case, but simply a scripting hack to adjust the death counter without actually killing/resurrecting someone.


Edited by Ardanis, 16 May 2017 - 02:55 PM.

"Uguu~ Boku Ayu."

Before you start breaking wall tiles with your bare fists, ask yourself first - do you truly need it?

#7 Avenger

Avenger
  • Modders
  • 3693 posts
  • Gender:Male
  • Location:Hungary

Posted 17 May 2017 - 07:55 AM

So, the only reason to ever use 8 chars or shorter variables is that some v1 effects cannot store longer variable names.

 

32 is the theoretical maximum for any variable name. 24 is the maximum if you want to set a variable via effects, like opcode 265. 18 is the maximum length of a scriptname (thus making a 32 max. "death variable"). And 8 is the maximum length of a variable if you don't want to use opcode 265 as external effect. (You can use only v1 effects in items/spells, but you can always call an external .eff).

 

Spoiler


#8 Creepin

Creepin
  • Members
  • 154 posts
  • Gender:Male
  • Location:Moscow

Posted 17 May 2017 - 12:47 PM

Wow that is whole another level of the issues to consider I wasn't even aware about! Thank you for your analysis Avenger! :worship:



#9 Ardanis

Ardanis

    A very GAR character

  • Modders
  • 2545 posts
  • Gender:Male
  • Location:Saint-Petersburg, Russia

Posted 17 May 2017 - 11:36 PM

By the way, this is only half true:

stick with 8 symbols variable names even though SetGlobal("GOBLIN_QUEST_DID_DOG_SMELLED_MEDALLION","GLOBAL",1) is much more obvious and easy to track than SetGlobal("CRVAR034","GLOBAL",1)

 

If you got a very big quest (or even several ones) with a lot of events and stages to track, you're better off with systemic naming to keep it organized and maintainable. The SoD's bd_poison_dsc_supplies is actually a poor example of naming, compared to e.g. subquest variables that use quest ID label as a prefix and follow with a brief one-word description. Of course, this is only relevant if you work on something comparable in size and need to search in files often.


Edited by Ardanis, 17 May 2017 - 11:39 PM.

"Uguu~ Boku Ayu."

Before you start breaking wall tiles with your bare fists, ask yourself first - do you truly need it?



Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users