K
Kyle Conway
Guest
Well I have a problem but not really sure where to start. Basically I have a weapon system set up in an array with ds_maps in the create even of oWeapon.
and in the bottom I have code to determine which weapon is out at a given time.
ChangeWeapon is a script:
QUESTION: Everything works fine, but when I set up a save system, I attempted to save "global.currentweapon". When I reload the game it works, (I have a string listing current weapon and draws to the screen). So the game is saving the variable and replacing it when loaded as I would hope. However my weapon is not switching to the weapon that was out. Instead it defaults to weapon[0]. It may be important to note that oWeapon is persistent, and if I click (fire a weapon) after loading before switching to another weapon, it breaks the game.
I assume the problem to be in this code:
...as shown before. If i had to guess I would say the global.currentweapon = 0; is changing it to 0 after loading, or something like that. the global variable was previously in another object that stores all my global variables. however without it there, I get an error of the variable not existing before being read. Ultimately I guess I'm not really sure what the problem is, if anyone knows a solution or work around it would be greatly appreciated!
Code:
//AR
weapons[2] = ds_map_create();
ds_map_add(weapons[2],"sprite",sAR);
ds_map_add(weapons[2],"recoil",25);
ds_map_add(weapons[2],"recoil_push",0);
ds_map_add(weapons[2],"damage",1);
ds_map_add(weapons[2],"projectile",oPistol_Bullet);
ds_map_add(weapons[2],"startup",0);
ds_map_add(weapons[2],"length",10);
ds_map_add(weapons[2],"cooldown",10);
ds_map_add(weapons[2],"bulletspeed",50);
ds_map_add(weapons[2],"automatic",true);
Code:
global.currentweapon = 0;
weapon = global.currentweapon;
ChangeWeapon(weapon);
Code:
weapon = argument0;
var wp_map = weapons[weapon];
sprite = ds_map_find_value(wp_map, "sprite");
recoil = wp_map[? "recoil"];
recoil_push = wp_map[? "recoil_push"];
damage = wp_map[? "damage"];
projectile = wp_map[? "projectile"];
startup = wp_map[? "startup"];
length = wp_map[? "length"];
cooldown = wp_map[? "cooldown"];
bulletspeed = wp_map[? "bulletspeed"];
automatic = wp_map[? "automatic"];
I assume the problem to be in this code:
Code:
global.currentweapon = 0;
weapon = global.currentweapon;
ChangeWeapon(weapon);