ID:151236
 
Okay, I am trying to make a spell system wherein spell bjects are stored inside a spellbook object. A "cast" verb allows access to these objs. However, when I try to execute the verb I get a list index out of bounds error. Here's the relevant code:

obj/proc/do_spell(obj/spell, target)
{
        if (!istype(target, spell.V1))
        {
                usr << "Invalid target. You may only target a [spell.V1] with this spell."
                return 0
        }
        for (x=1, x

Yes, I realize the len assignment in the obj is redundant, but flat out assigning values to the list index produced errors at runtime.
Any thoughts?
-James
On 1/31/01 9:03 am jmurph wrote:
Okay, I am trying to make a spell system wherein spell bjects are stored inside a spellbook object. A "cast" verb allows access to these objs. However, when I try to execute the verb I get a list index out of bounds error.

Which line is giving you the error?

If the line is not reported when you compile, then you should turn on extra debugging info, which you do like so:

#define DEBUG

Knowing the line will make all the difference.
In response to Deadron (#1)
Which line is giving you the error?
switch ("[spell.AFFECTS[x][1]]")

-James
On 1/31/01 9:03 am jmurph wrote:
Okay, I am trying to make a spell system wherein spell bjects are stored inside a spellbook object. A "cast" verb allows access to these objs. However, when I try to execute the verb I get a list index out of bounds error...
Any thoughts?

Well I see all sorts of stuff I don't understand there, probably because this is excerpts of the code...

So I'll fall back on this one: How about simplifying this by tossing the multi-dimensional arrays and using a simple object instead? I know that the array approach comes from C-based programming, so it's what many are used to...but it's really not necessary or desirable. It encourages more bugs by not letting the compiler know what's up.

If you created an lightweight affects object, it would serve as a structure with the added benefits of compiler checking and no index problems, and you might find the code a bit more readable.

Then the code would look something like this (I'm guessing at what some of this is):

spell_affect
nature // DAMAGE, DAMAGE_NOARMOR, HEAL, AFFECT
level // How tough this affect is
damage // How much damage it does
damage_type // DAM_ACID

//skip to the spell obj
acid_splash
name = "acid blast"
V1 = /mob
MATERIAL = "chants, \"HOORAY\""
SOUND = 'magic1.wav'
New()
AFFECTS = new()
AFFECTS.nature = "DAMAGE"
AFFECTS.level = 4
AFFECTS.damage = 24
AFFECTS.damage_type = "DAM_ACID"

etc.
In response to Deadron (#3)
I realized after posting my response that you have your game architected to allow multiple affects for a spell...so to use what I suggested, you would just give the spell a list of affect spells, and iterate through each.

Also, the problems you are having with lists are probably in how the multi-dimensional list is being declared (the len thing).

You probably want to create the affects multi-dimensional list in this manner (taken from the list reference entry):

var/grid = new/list(10,5)
In response to Deadron (#4)
You probably want to create the affects multi-dimensional list in this manner (taken from the list reference entry):

var/grid = new/list(10,5)

Well, this shouldn't make a difference since var/temp[10][5] would be equivalent, but I tried your suggestion anyway and I get the same error. I think it may be something with how lists are managed....

-James
In response to Jmurph (#5)
Okay, well maybe I *did* forget to do a var/X....
*slaps self silly*

-James