Jump to content

Photo

Misc. Compatibility Library


  • Please log in to reply
4 replies to this topic

#1 grayswandir

grayswandir

    semi-genius

  • Members

Posted 16 May 2013 - 02:42 PM

I was thinking of writing a small little library that, instead of having this (ripped from ghost.zh):
// npc->Misc[] index
// Set this so it doesn't conflict with other scripts. Legal values are 0-15.
const int __GHI_GHZH_DATA = 15;
 
You'd have something like this:
// npc->Misc[] index
int __GHI_GHZH_DATA = RegisterIndex(INDEX_NPC_MISC);
 
If all the different scripts you'd use would call a register function instead of assigning an arbitrary index, then you wouldn't have to worry about managing these constants, the code would take care of that for you.
 
 
Anyway, if I wrote this, would people use it? Because if I end up being the only one using it, it'd be kind of pointless. :P

#2 Kite

Kite

    ???

  • Members

Posted 16 May 2013 - 02:55 PM

I think the main advantage of having constants is that they don't take up variable memory that can be used for other variables that are actually dynamic. Constants are instead deciphered at compile time, so they don't take up any variable memory since they are not really variables by the time ZC is running the script. While having a better method of defining script settings would be nice, I'm not sure if the memory tradeoff would be worth it since there is a limit to how much memory is used for global variables (which are stashed into the save information) and other types of scripts. :shrug:


Edited by Nick, 16 May 2013 - 02:59 PM.


#3 grayswandir

grayswandir

    semi-genius

  • Members

Posted 16 May 2013 - 04:05 PM

Is ZC really that hurting for memory? Should I start watching how many global variables I use? Or do you just mean that the gain is so small it's not really worth it? :P


As an aside, is there a description of ZC's memory management / variable scoping anywhere? What is the point of putting things in script blocks, aside from the run() function. Are variables declared in a script local to that script? etc.? I've been getting by fine so far, but I have no way to know if I'm accidentally eating large amounts of memory or something else bad because I have no idea how the underlying mechanics work. :shrug: No problem if there isn't, I'm just feel vaguely uneasy from second-guessing myself on this all the time.

#4 Saffith

Saffith

    IPv7 user

  • Members

Posted 16 May 2013 - 06:53 PM

There's a maximum of 256 global variables. I'm not sure about local variables, but I think it's 256 per script. There's also a limit of 4096 arrays at once, but there's no limit on array size.


Another issue: you can't initialize global variables that way. It would have to be done in the Init script, and if you're doing that, you might as well just assign them values.

#5 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 16 May 2013 - 09:58 PM

The proper solution would be enums, but we don't have those. Preprocessor magic could also work, but would be even more ugly. const int is the least evil option right now.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users