J
jvks2
Guest
Hello, I am using GM 101's tutorial for a weapon changing array and below is the error message I ran into when trying to get it to run. I have tried a few different things and can't get it to run. I tried to include all the relevant code below.
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object Obj_bow_break:
Variable Obj_bow_break.weapon(100165, -2147483648) not set before reading it.
at gml_Object_Obj_bow_break_DrawEvent_1 (line 2) - image_index = global.weapon_array[weapon, 1];
############################################################################################
Here's the script:
// [0] break arrow
global.weapon_array[0,0] = "Arrow Break"; //Name
global.weapon_array[0,1] = Spr_bow_break; //Spr_arrow_break; //Sprite Index
global.weapon_array[0,2] = 10; //Rate of Fire
global.weapon_array[0,3] = Obj_arrow_break; //Ammo Index
global.weapon_array[0,4] = 43; //Muzzle Offset for projectile creation
global.weapon_array[0,5] = 0; //x offset for weapon placement
global.weapon_array[0,6] = -20; //y offset for weapon placement
// [1] fixes arrow
global.weapon_array[1,0] = "Arrow Fix"; //Name
global.weapon_array[1,1] = Spr_bow_fixes; //Spr_arrow_fixes; //Sprite Index
global.weapon_array[1,2] = 10; //Rate of Fire
global.weapon_array[1,3] = Obj_arrow_fixes; //Ammo Index
global.weapon_array[1,4] = 43; //Muzzle Offset for projectile creation
global.weapon_array[1,5] = 0; //x offset for weapon placement
global.weapon_array[1,6] = -20; //y offset for weapon placement
it repeats a few times for new arrows
Here is the controller main that is in the first room:
global.weapons = 4;
Scr_weapon_array();
Here is one of the weapons:
CREATE:
//Firing variables
firing = false;
canFire = true;
rateOfFire = 25;
ALARM0:
canFire = true;
STEP:
//Depth of bow
depth = -y + Obj_player.y_offset - 1;
//Set Direction Towards Mouse
image_angle = point_direction(x,y,mouse_x,mouse_y);
if(mouse_x < x) image_yscale = -1
else image_yscale = 1
GLOBAL LEFT PRESSED:
//added stuff && can_shoot
if(canFire)
{
//alarm[0] = global.weaponArray[weapon, 2];
alarm[0] = rateOfFire;
canFire = false;
firing = true;
if(instance_exists(Obj_arrow))
{
firing = false;
/*x = Obj_arrow.x
y = Obj_arrow.y
*/
with (Obj_arrow)
{
instance_destroy()
}
}
else
{
instance_create(x + lengthdir_x(15, image_angle),y + lengthdir_y(10, image_angle),Obj_arrow);
}
}
MOUSE WHEEL UP:
if (weapon < global.weapons)
{
weapon++;
}
else{
weapon = 0;
}
MOUSE WHEEL DOWN:
if (weapon > global.weapons)
{
weapon--;
}
else{
weapon = global.weapons;
}
DRAW:
draw_self();
image_index = global.weapon_array[weapon, 1];
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object Obj_bow_break:
Variable Obj_bow_break.weapon(100165, -2147483648) not set before reading it.
at gml_Object_Obj_bow_break_DrawEvent_1 (line 2) - image_index = global.weapon_array[weapon, 1];
############################################################################################
Here's the script:
// [0] break arrow
global.weapon_array[0,0] = "Arrow Break"; //Name
global.weapon_array[0,1] = Spr_bow_break; //Spr_arrow_break; //Sprite Index
global.weapon_array[0,2] = 10; //Rate of Fire
global.weapon_array[0,3] = Obj_arrow_break; //Ammo Index
global.weapon_array[0,4] = 43; //Muzzle Offset for projectile creation
global.weapon_array[0,5] = 0; //x offset for weapon placement
global.weapon_array[0,6] = -20; //y offset for weapon placement
// [1] fixes arrow
global.weapon_array[1,0] = "Arrow Fix"; //Name
global.weapon_array[1,1] = Spr_bow_fixes; //Spr_arrow_fixes; //Sprite Index
global.weapon_array[1,2] = 10; //Rate of Fire
global.weapon_array[1,3] = Obj_arrow_fixes; //Ammo Index
global.weapon_array[1,4] = 43; //Muzzle Offset for projectile creation
global.weapon_array[1,5] = 0; //x offset for weapon placement
global.weapon_array[1,6] = -20; //y offset for weapon placement
it repeats a few times for new arrows
Here is the controller main that is in the first room:
global.weapons = 4;
Scr_weapon_array();
Here is one of the weapons:
CREATE:
//Firing variables
firing = false;
canFire = true;
rateOfFire = 25;
ALARM0:
canFire = true;
STEP:
//Depth of bow
depth = -y + Obj_player.y_offset - 1;
//Set Direction Towards Mouse
image_angle = point_direction(x,y,mouse_x,mouse_y);
if(mouse_x < x) image_yscale = -1
else image_yscale = 1
GLOBAL LEFT PRESSED:
//added stuff && can_shoot
if(canFire)
{
//alarm[0] = global.weaponArray[weapon, 2];
alarm[0] = rateOfFire;
canFire = false;
firing = true;
if(instance_exists(Obj_arrow))
{
firing = false;
/*x = Obj_arrow.x
y = Obj_arrow.y
*/
with (Obj_arrow)
{
instance_destroy()
}
}
else
{
instance_create(x + lengthdir_x(15, image_angle),y + lengthdir_y(10, image_angle),Obj_arrow);
}
}
MOUSE WHEEL UP:
if (weapon < global.weapons)
{
weapon++;
}
else{
weapon = 0;
}
MOUSE WHEEL DOWN:
if (weapon > global.weapons)
{
weapon--;
}
else{
weapon = global.weapons;
}
DRAW:
draw_self();
image_index = global.weapon_array[weapon, 1];