ID:148210
 
Ok, I'm working on a new racing game, and my problem is this...when I am in 5th gear and I try to down shift, it gets a runtime error, this one:

runtime error: list index out of bounds
proc name: Shift Down (/mob/verb/Shift_Down)
source file: main.dm,249
usr: Goku72 (/mob)
src: Goku72 (/mob)
call stack:


That's the only gear having problems when I downshift. I have no idea why, here's my downshift code...

        Shift_Down()
if(!usr.gear.len)
return 0
else
if((usr.currentgear%usr.gear.len)-1)
usr.currentgear=(usr.currentgear%usr.gear.len)-1
usr<<"<b>You shift to [usr.gear[usr.currentgear]]</b>"
return usr.currentgear
else
return 0
Goku72 wrote:
>       Shift_Down()
> if(!usr.gear.len)
> return 0
> else
> if((usr.currentgear%usr.gear.len)-1)
> usr.currentgear=(usr.currentgear%usr.gear.len)-1
> usr<<"<b>You shift to [usr.gear[usr.currentgear]]</b>"
> return usr.currentgear
> else
> return 0
>


usr.currentgear must be getting set to a bad value...to figure out what is happening, put in some debugging checks on the value...if it's less than 1 or larger than currentgear.len, report what it is without trying to do the downshift. (The ASSERT() proc is helpful for this sort of thing.)
In response to Deadron
I tried using ASSERT(), but I wasn't quite sure how to use it. I looked it up in the reference, it didn't express how to use it. Just told me to give it an argument.

This is how my list is defined:

list
currentgear[0]
gear[0]


And this is how I add the gears and such to it:
proc
AddGears()
src.gear=new
src.gear.Add("R")
src.gear.Add("N")
var/gearmax=1
while(src.highestgear>=gearmax)
src.gear.Add(num2text(gearmax))
gearmax++
if((src.currentgear%src.gear.len)>2)
src.currentgear=(src.currentgear%src.gear.len)-1
else
src.currentgear=(src.currentgear%src.gear.len)+2
In response to Goku72
ASSERT() is exactly like an if() statement, but it causes the proc to crash with an error message if it's false.