Unfortunately, what you want to do in its current state is impossible.

Why? The preprocessor converts "MAX_CLASS" to a string literal "5" for example before the compiler takes a stab at it. The compiler is able to allocated fixed memory on the stack because the value is constant. When MAX_CLASS is a variable, memory must come from the heap, and you must do all the assignment yourself.
Therefore, your structure will need to be something like this, now:
struct    skill_type
{
  char *    name;
  sh_int    **skill_level;
  sh_int    **rating;

And all your skill loads will have to dynamically assign skill_level and rating. That means you can no longer use a flat const skill table, sorry. (Or, at least, it can be flat except for the variable aspects which will have to be located elsewhere, i.e. a read/write skills.dat file. Otherwise how will adding a classe magically transform 5 ints for skill_level to 6?) I wrote a dynamic Skill Builder/Loader in C++ for a version of ROM I have if you'd like to take a look. It writes/reads skills from disk on boot, but it's a little hackish as I never finished it.
-- Jeremy



Tristan M wrote:

i think i worded that subject correctly...anyway, what i want to do is load my classes from a file. ive put together my own class editor which works perfectly(prolly littered with memory leaks i dont kno about tho:p) except that now that classes load from a file, i want to change all those MAX_CLASS's around to maxClass, which is set when load_class is executed during the boot, and changed if classes are created online...so for example in merc.h:

...
...
struct    skill_type
{
   char *    name;            /* Name of skill        */
   sh_int    skill_level[MAX_CLASS]; <--- change this to [maxClass]
   sh_int    rating[MAX_CLASS];<--- change this to [maxClass]
   SPELL_FUN *    spell_fun;        /* Spell pointer (for spells)    */
   sh_int    target;            /* Legal targets        */
   sh_int    minimum_position;    /* Position for caster / user    */
...
...

so i changed the [MAX_CLASS] 's to [maxClass] just to see what would happen and this came out:
rom24\src\merc.h(1838) : error C2057: expected constant expression
rom24\src\merc.h(1839) : error C2057: expected constant expression
rom24\src\merc.h(1839) : error C2229: struct 'skill_type' has an illegal zero-sized array rom24\src\merc.h(1840) : error C2229: struct 'skill_type' has an illegal zero-sized array

and i probably sound like a newb asking this, but thats ok.



Reply via email to