• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Weapons are not working

Q

Qaletaqa Thorson

Guest
this is the error i get when i pick up any weapon

_________________________________________
############################################################################################ FATAL ERROR in action number 1 of Step Event0 for object oPowerup: lengthdir_x argument 1 incorrect type (undefined) expecting a Number (YYGF) at gml_Object_oPowerup_Step_0 (line 35) - x_speed -= lengthdir_x(other.Recoil_Push,other.direction); ############################################################################################ -------------------------------------------------------------------------------------------- stack frame is gml_Object_oPowerup_Step_0 (line 35)
 
Q

Qaletaqa Thorson

Guest
Create Event:
/// @description Vars
// No Poweerup
weapons[0] = ds_map_create();
ds_map_add(weapons[0],"sprite",-1);
ds_map_add(weapons[0],"Recoil",0);
ds_map_add(weapons[0],"Recoil_Push",0);
ds_map_add(weapons[0],"damage",0);
ds_map_add(weapons[0],"projectile",-1);
ds_map_add(weapons[0],"startup",0);
ds_map_add(weapons[0],"length",0);
ds_map_add(weapons[0],"cooldown",0);
ds_map_add(weapons[0],"bulletspeed",0);
ds_map_add(weapons[0],"automatic",false);

//Pistol
weapons[1] = ds_map_create();
ds_map_add(weapons[1],"sprite",sPistolHeld);
ds_map_add(weapons[1],"Recoil",1);
ds_map_add(weapons[1],"Recoil_Push",0);
ds_map_add(weapons[1],"damage",2);
ds_map_add(weapons[1],"projectile",oBullet);
ds_map_add(weapons[1],"startup",0);
ds_map_add(weapons[1],"length",2);
ds_map_add(weapons[1],"cooldown",1);
ds_map_add(weapons[1],"bulletspeed",0);
ds_map_add(weapons[1],"automatic",false);

//MachineGun
weapons[2] = ds_map_create();
ds_map_add(weapons[2],"sprite",sMachinegunHeld);
ds_map_add(weapons[2],"Recoil",2);
ds_map_add(weapons[2],"Recoil_Push",0);
ds_map_add(weapons[2],"damage",3);
ds_map_add(weapons[2],"projectile",oBullet);
ds_map_add(weapons[2],"startup",0);
ds_map_add(weapons[2],"length",2);
ds_map_add(weapons[2],"cooldown",1);
ds_map_add(weapons[2],"bulletspeed",10);
ds_map_add(weapons[2],"automatic",true);

//Shotgun
weapons[3] = ds_map_create();
ds_map_add(weapons[3],"sprite",sShotgunHeld);
ds_map_add(weapons[3],"Recoil",4);
ds_map_add(weapons[3],"Recoil_Push",5);
ds_map_add(weapons[3],"damage",20);
ds_map_add(weapons[3],"projectile",oBullet);
ds_map_add(weapons[3],"startup",3);
ds_map_add(weapons[3],"length",2);
ds_map_add(weapons[3],"cooldown",4);
ds_map_add(weapons[3],"bulletspeed",5);
ds_map_add(weapons[3],"automatic",false);

//Sniper
weapons[4] = ds_map_create();
ds_map_add(weapons[4],"sprite",sSniperHeld);
ds_map_add(weapons[4],"Recoil",4);
ds_map_add(weapons[4],"Recoil_Push",2);
ds_map_add(weapons[4],"damage",15);
ds_map_add(weapons[4],"projectile",oBullet);
ds_map_add(weapons[4],"startup",3);
ds_map_add(weapons[4],"length",2);
ds_map_add(weapons[4],"cooldown",4);
ds_map_add(weapons[4],"bulletspeed",15);
ds_map_add(weapons[4],"automatic",false);

//Bazoka
weapons[5] = ds_map_create();
ds_map_add(weapons[5],"sprite",sBazookaHeld);
ds_map_add(weapons[5],"Recoil",5);
ds_map_add(weapons[5],"Recoil_Push",10);
ds_map_add(weapons[5],"damage",5);
ds_map_add(weapons[5],"projectile",oRocket);
ds_map_add(weapons[5],"startup",5);
ds_map_add(weapons[5],"length",2);
ds_map_add(weapons[5],"cooldown",5);
ds_map_add(weapons[5],"bulletspeed",15);
ds_map_add(weapons[5],"automatic",false);

//Flamethrower
weapons[6] = ds_map_create();
ds_map_add(weapons[6],"sprite",sFlamethrowerHeld);
ds_map_add(weapons[6],"Recoil",1);
ds_map_add(weapons[6],"Recoil_Push",3);
ds_map_add(weapons[6],"damage",15);
ds_map_add(weapons[6],"projectile",oFire);
ds_map_add(weapons[6],"startup",3);
ds_map_add(weapons[6],"length",2);
ds_map_add(weapons[6],"cooldown",0);
ds_map_add(weapons[6],"bulletspeed",20);
ds_map_add(weapons[6],"automatic",false);

//Equiped
weapon = 0;
Ammo[array_length_1d(weapons)-1] = 0;
Ammo[0] = 0;

//Equip New Weapon
ChangeWeapon(0);

//??
current_cd = 0;
current_delay = 0;
current_recoil = 0;

Step Event:
/// @description Powerups
// Gun Align
x = oPlayer.x;
y = oPlayer.y;
direction = point_direction(x,y, mouse_x, mouse_y);
if (direction > 90) && (direction < 270) image_yscale = -1; else image_yscale = 1;
image_angle = direction;

//Shooting
var MouseB;
if (automatic) MouseB = mouse_check_button(mb_left); else MouseB = mouse_check_button_pressed(mb_left);

if (MouseB)
{
if (current_cd == 0)
{
current_cd = cooldown;
current_delay = startup;
}
}

if (current_cd == 0) && (projectile != -1)
{
if (Ammo[weapon] != 0)
{
with (instance_create_layer(x+lengthdir_x(length,direction), y+lengthdir_y(length,direction), "Instances_Bullet", projectile))
{
direction = other.direction;
speed = other.bulletspeed;
}
Ammo[weapon] -=1;
}
with (oPlayer)
{
x_speed -= lengthdir_x(other.Recoil_Push,other.direction); //this is where the error is and i don't understand how to fix it
y_speed -= lengthdir_y(other.Recoil_Push,other.direction);

}
current_recoil = recoil;
}

current_delay = max(-1,current_delay-1);
if (current_delay == -1) current_cd = max(0,current_cd-1);
current_recoil = max(0,floor(current_recoil*0.8));

depth = oPlayer.depth-1;

Draw Event:
/// @description Draw Weapons
// show Weapons
if (sprite != -1)
{
draw_sprite_ext(
sprite,
image_index,
x-lengthdir_x(current_recoil, direction),
y-lengthdir_y(current_recoil, direction),
image_xscale,
image_yscale,
image_angle,
image_blend,
image_alpha
);
}

the Script i'm using for the weapons themselves
//Equip New Weapon
weapon = argument0;
var wp_map = weapons[weapon];
sprite = 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"];
 

Slyddar

Member
x_speed -= lengthdir_x(other.Recoil_Push,other.direction); //this is where the error is and i don't understand how to fix it
y_speed -= lengthdir_y(other.Recoil_Push,other.direction);
Try wrapping your code in [.code.] and [./code.] (without the periods) so it's easier for people to read and help.

You need to refer to the weapon ds_map you are using with weapons. Recoil_Push is just a ds_map entry, you have to refer to it in the map with ds_map[? "Recoil_Push"]. Also you are using capitals and lowercase randomly. You should just make every variable lowercase to avoid confusion, and errors.
 
Q

Qaletaqa Thorson

Guest
Try wrapping your code in [.code.] and [./code.] (without the periods) so it's easier for people to read and help.

You need to refer to the weapon ds_map you are using with weapons. Recoil_Push is just a ds_map entry, you have to refer to it in the map with ds_map[? "Recoil_Push"]. Also you are using capitals and lowercase randomly. You should just make every variable lowercase to avoid confusion, and errors.
thank you for the reply (and the advice) but i fixed this earlier today (and felt like a right idiot when i realized what was wrong) my current problem is:
ERROR!!! :: ############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object oPowerup:


undefined value
at gml_Object_oPowerup_Step_0 (line 43) - current_recoil = max(0,floor(current_recoil*0.8));
############################################################################################
once again any help would be appreciated
 
Q

Qaletaqa Thorson

Guest
It might be complaining about the line a few up, as recoil should be wp_map[? "recoil"]; maybe.

Code:
current_recoil = recoil;
just tried that, unfortunately not so thanks anyway bud
 
Q

Qaletaqa Thorson

Guest
it just one thing after another with this, the current problems are:
one the weapon wont appear when i've picked it up
or when i use it in the game im trying to build, this happens:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object oPowerup:

undefined value
at gml_Object_oPowerup_Step_0 (line 43) - current_recoil = max(0,floor(current_recoil*0.8));
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_oPowerup_Step_0 (line 43)
 
Q

Qaletaqa Thorson

Guest
the Test where the Guns wont appear on the character:
oPowerUp Create:
/// @description Vars
// No Poweerup
weapons[0] = ds_map_create();
ds_map_add(weapons[0],"sprite",-1);
ds_map_add(weapons[0],"Recoil",0);
ds_map_add(weapons[0],"Recoil_Push",0);
ds_map_add(weapons[0],"damage",0);
ds_map_add(weapons[0],"projectile",-1);
ds_map_add(weapons[0],"startup",0);
ds_map_add(weapons[0],"length",0);
ds_map_add(weapons[0],"cooldown",0);
ds_map_add(weapons[0],"bulletspeed",0);
ds_map_add(weapons[0],"automatic",false);

//Pistol
weapons[1] = ds_map_create();
ds_map_add(weapons[1],"sprite",sPistolHeld);
ds_map_add(weapons[1],"Recoil",1);
ds_map_add(weapons[1],"Recoil_Push",0);
ds_map_add(weapons[1],"damage",2);
ds_map_add(weapons[1],"projectile",oBullet);
ds_map_add(weapons[1],"startup",0);
ds_map_add(weapons[1],"length",2);
ds_map_add(weapons[1],"cooldown",1);
ds_map_add(weapons[1],"bulletspeed",0);
ds_map_add(weapons[1],"automatic",false);

//MachineGun
weapons[2] = ds_map_create();
ds_map_add(weapons[2],"sprite",sMachinegunHeld);
ds_map_add(weapons[2],"Recoil",2);
ds_map_add(weapons[2],"Recoil_Push",0);
ds_map_add(weapons[2],"damage",3);
ds_map_add(weapons[2],"projectile",oBullet);
ds_map_add(weapons[2],"startup",0);
ds_map_add(weapons[2],"length",2);
ds_map_add(weapons[2],"cooldown",1);
ds_map_add(weapons[2],"bulletspeed",10);
ds_map_add(weapons[2],"automatic",true);

//Shotgun
weapons[3] = ds_map_create();
ds_map_add(weapons[3],"sprite",sShotgunHeld);
ds_map_add(weapons[3],"Recoil",4);
ds_map_add(weapons[3],"Recoil_Push",5);
ds_map_add(weapons[3],"damage",20);
ds_map_add(weapons[3],"projectile",oBullet);
ds_map_add(weapons[3],"startup",3);
ds_map_add(weapons[3],"length",2);
ds_map_add(weapons[3],"cooldown",4);
ds_map_add(weapons[3],"bulletspeed",5);
ds_map_add(weapons[3],"automatic",false);

//Sniper
weapons[4] = ds_map_create();
ds_map_add(weapons[4],"sprite",sSniperHeld);
ds_map_add(weapons[4],"Recoil",4);
ds_map_add(weapons[4],"Recoil_Push",2);
ds_map_add(weapons[4],"damage",15);
ds_map_add(weapons[4],"projectile",oBullet);
ds_map_add(weapons[4],"startup",3);
ds_map_add(weapons[4],"length",2);
ds_map_add(weapons[4],"cooldown",4);
ds_map_add(weapons[4],"bulletspeed",15);
ds_map_add(weapons[4],"automatic",false);

//Bazoka
weapons[5] = ds_map_create();
ds_map_add(weapons[5],"sprite",sBazookaHeld);
ds_map_add(weapons[5],"Recoil",5);
ds_map_add(weapons[5],"Recoil_Push",10);
ds_map_add(weapons[5],"damage",5);
ds_map_add(weapons[5],"projectile",oRocket);
ds_map_add(weapons[5],"startup",5);
ds_map_add(weapons[5],"length",2);
ds_map_add(weapons[5],"cooldown",5);
ds_map_add(weapons[5],"bulletspeed",15);
ds_map_add(weapons[5],"automatic",false);

//Equiped
weapon = 0;
Ammo[array_length_1d(weapons)-1] = 0;
Ammo[0] = 0;

//Equip New Weapon
ChangeWeapon(0);

//Recoil
current_cd = 0;
current_delay = -1;
current_recoil = 0;

oPowerUp Step:
/// @description Powerups
// Gun Align
x = oPlayer.x;
y = oPlayer.y;
direction = point_direction(x,y, mouse_x, mouse_y);
if (direction > 90) && (direction < 270) image_yscale = -1; else image_yscale = 1;
image_angle = direction;

//Shooting
var MouseB;
if (automatic) MouseB = mouse_check_button(mb_left); else MouseB = mouse_check_button_pressed(mb_left);

if (MouseB)
{
if (current_cd == 0)
{
current_cd = cooldown;
current_delay = startup;
}
}

if (current_cd == 0) && (projectile != -1)
{
if (Ammo[weapon] != 0)
{
with (instance_create_layer(x+lengthdir_x(length,direction), y+lengthdir_y(length,direction), "Instances_Bullet", projectile))
{
direction = other.direction;
speed = other.bulletspeed;
}
Ammo[weapon] -=1;
}
with (oPlayer)
{
x_speed -= lengthdir_x(other.Recoil_Push,other.direction);
y_speed -= lengthdir_y(other.Recoil_Push,other.direction);
}
current_recoil = recoil;
}

current_delay = max(-1,current_delay-1);
if (current_delay == -1) current_cd = max(0,current_cd-1);
current_recoil = max(0,floor(current_recoil*0.8));

depth = oPlayer.depth-1;

oPowerUp Draw:
/// @description Draw Weapons
// show Weapons
if (sprite != -1)
{
draw_sprite_ext(
sprite,
image_index,
x-lengthdir_x(current_recoil, direction),
y-lengthdir_y(current_recoil, direction),
image_xscale,
image_yscale,
image_angle,
image_blend,
image_alpha
);
}

litteraly the same code as the afore mentioned game how is this not working?

https://drive.google.com/file/d/1FxyFHoqLz0BZ8VgAw_i_rTsoPC5TMAvX/view?usp=sharing - the Guns not working properly
 

Slyddar

Member
Like I mentioned already, change all your capital letter variables to lower case.
You have ds_map_add(weapons[5],"Recoil",5); in the create, but are then trying to assign it with current_recoil = recoil; in the step.
 
Top