probs destroying ds lists...

P

philman401

Guest
So I'm making a rpg game. I have scripts that initializes their stats stored in a map type ds list.

I have scripts for each class, and a script that calls for all of them.

Code:
//knight
iniKnight();
//thief
iniThief();
//mage
iniMage();
//cleric
iniCleric();
//archer
iniArcher();

global.selClass := 0;
global.classList := ds_list_create();
ds_list_add(global.classList,global.classKnight);
ds_list_add(global.classList,global.classThief);
ds_list_add(global.classList,global.classMage);
ds_list_add(global.classList,global.classCleric);
ds_list_add(global.classList,global.classArcher);
iniUniStats();

I also have a script to "clean the game" ie destroy the ds lists I've created for use when the game session ends (not app end, but like return to main menu or something). However, when I call upon this script to delete some ds lists, I get an errror basically saying some of these lists don't exist. Mainly, the mage, cleric an darcher. I've done nothing different to them, yet they are giving me issues.

here is an example of the knight

Code:
global.classKnight := ds_map_create();
global.classKnight[? "object"] := knight;
global.classKnight[? "class"] := "Knight";
global.classKnight[? "spr_rite"] := knightrite_spr;
global.classKnight[? "spr_left"] := knightleft_spr;
global.classKnight[? "maxhp"] := irandom_range(125,200);
global.classKnight[? "maxmp"] := irandom_range(15,25);;
global.classKnight[? "hp"] := global.classKnight[? "maxhp"];
global.classKnight[? "mp"] := 0;
global.classKnight[? "power"] := irandom_range(3,8);
var pr := global.classKnight[? "power"];
var prmn := irandom_range(3,5)/100;
var prmx := irandom_range(3,5)/100;
global.classKnight[? "prmin"] := pr * prmn;
global.classKnight[? "prmax"] := pr * prmx;
global.classKnight[? "recovery"] := irandom_range(1,2);
global.classKnight[? "attack_spd"] := irandom_range(30,60);
global.classKnight[? "dr"] := irandom_range(15,25)/100;
global.classKnight[? "crits"] := irandom_range(5,10);
global.classKnight[? "crit_dmg"] := irandom_range(100,150)/100;
global.classKnight[? "speechcraft"] := irandom_range(10,15);
global.classKnight[? "pesonality"] := choose("charismatic","diplomatic","righteous");
global.classKnight[? "act_ab"] := "script goes here";
global.classKnight[? "pass_ab"] := "script goes here";
global.classKnight[? "level"] := 1;
global.classKnight[? "maxlevel"] := 100;
global.classKnight[? "exp"] := 0;
global.classKnight[? "maxexp"] := 100;
global.classKnight[? "expgrowth"] := 50;
global.classKnight[? "name"] := "Knight";

here us the ine for mage (the one with the issue, along with cleric and archer)
Code:
global.classMage := ds_map_create();
global.classMage[? "object"] := mage;
global.classMage[? "class"] := "Mage";
global.classMage[? "spr_rite"] := magerite_spr;
global.classMage[? "spr_left"] := mageleft_spr;
global.classMage[? "maxhp"] := irandom_range(90,110);
global.classMage[? "maxmp"] := irandom_range(75,95);;
global.classMage[? "hp"] := global.classMage[? "maxhp"];
global.classMage[? "mp"] := 0;
global.classMage[? "power"] := irandom_range(10,15);
var pr := global.classMage[? "power"];
var prmn := irandom_range(6,8)/100;
var prmx := irandom_range(5,7)/100;
global.classMage[? "prmin"] := pr * prmn;
global.classMage[? "prmax"] := pr * prmx;
global.classMage[? "recovery"] :=  irandom_range(3,6);
global.classMage[? "attack_spd"] := irandom_range(20,25);
global.classMage[? "dr"] := irandom_range(5,10)/100;
global.classMage[? "crits"] := irandom_range(5,10);
global.classMage[? "crit_dmg"] := irandom_range(110,125)/100;
global.classMage[? "speechcraft"] := irandom_range(10,15);
global.classMage[? "pesonality"] := choose("intelligent","arrogant","eccentric");
global.classMage[? "act_ab"] := "script goes here";
global.classMage[? "pass_ab"] := "script goes here";
global.classMage[? "level"] := 1;
global.classMage[? "maxlevel"] := 100;
global.classMage[? "exp"] := 0;
global.classMage[? "maxexp"] := 100;
global.classMage[? "expgrowth"] := 35;
global.classMage[? "name"] := "Mage";

And here is the script to destroy the lists. I've added a ds_exist hoping to have it fixed but still same issue.

Code:
if(ds_exists(global.classKnight,ds_type_map))
ds_list_destroy(global.classKnight);
if(ds_exists(global.classThief,ds_type_map))
ds_list_destroy(global.classThief);
if(ds_exists(global.classMage,ds_type_map))
ds_list_destroy(global.classMage);
if(ds_exists(global.classCleric,ds_type_map))
ds_list_destroy(global.classCleric);
if(ds_exists(global.classArcher,ds_type_map))
ds_list_destroy(global.classArcher);
if(ds_exists(global.classList,ds_type_list))
ds_list_destroy(global.classList);
if(ds_exists(global.uniStats,ds_type_list))
ds_list_destroy(global.uniStats);

Only the mage/cleric/archer ds lists are having trouble being destroyed, everything else including uniStats and classList don't give me that error.
 

The-any-Key

Member
When you destroy a ds structure. Make sure you set any variables that got the index to noone. So you don't accidentally try a access them or delete non existing structures.

But my guess that you accidentally replace the index in the globals to number values.

Why do you write := ?
 
P

philman401

Guest
EDIT: OOMG I'm so duuuuuumb. Was trying to delete the DS maps with the ds_list_destroy instead of ds_map_destroy >.> <.< Well problem solved thanks though. Now gonna find something to hit my face with.

Why do you write := ?
That's just what I'm used to doing code from using a different language.

Why are you checking if a ds_map exists when you're trying to delete lists?
I wasn't before. I added that after the error for testing to see if it'll not have the error.

I
 
Last edited by a moderator:

TheouAegis

Member
I wasn't before. I added that after the error for testing to see if it'll not have the error.
Well that would cause the error anyway. You check if a ds_map exists, it does, then you try to delete the list with the same index...but there isn't one ,so you get an error. So don't do that again.

Now run along and play.
 
Top