Enemy attack bugs

M

MIWICP86

Guest
A bit of context - I have been following a bunch of tutorials and playing about with Game Maker to make my own rpg, but had a creative break a while back. Came back to my game to continue working on it and a few bugs have appeared that weren't there before. Please note Game Maker is updated to most recent version.

So here is the bug...



HITBOX SCRIPT

Code:
/// @arg sprite
/// @arg x
/// @arg y
/// @arg angle
/// @arg frames
/// @arg target_array
/// @arg damage
/// @arg knockback
var _sprite = argument0;
var _x = argument1;
var _y = argument2;
var _angle = argument3;
var _frames = argument4;
var _array = argument5;
var _damage = argument6;
var _knockback = argument7;

var _hitbox = instance_create_layer(_x, _y, "Instances", obj_hitbox);
_hitbox.sprite_index = _sprite;
_hitbox.image_angle = _angle;
_hitbox.alarm[0] = _frames;
_hitbox.targets_ = _array;
_hitbox.damage_ = _damage;
_hitbox.knockback_ = _knockback;

return _hitbox;
ATTACK STATE
Code:
/// @description attack state
image_speed = 1;
sprite_index = spr_bogger_attack_right;
set_sprite_facing()
if animation_hit_frame(2) {
    
    var _damage = 1;
    var _knockback = 20;
    var _life = 2;
    var _hitbox = create_hitbox (spr_bogger_grunt_hitbox, x, y+10, [], _life, [obj_idle_up, obj_shield_bubble], _damage, _knockback);
    audio_play_sound(a_bogger_attack, 5, false);
}



if animation_hit_frame (image_number - 1) {
    state_ = bogger.idle;
    sprite_index = spr_bogger_run_right;
    alarm[1] = 2 * global.one_second;
}
STEP
Code:
depth =- y;
if health_ <= 0 && state_ != enemy.attack {
    instance_destroy ();
}

if state_ != noone {
    event_user (state_);   
}
Also on the Attack State this keeps popping up. If this is the reason for the bug, where do I need to put the variable _hitbox so its mentioned the appropriate amount?



Apologies if I've made any mistakes and if also this is a stupidly easy bug to fix, I'm very new at programming.

Cheers
 

FrostyCat

Redemption Seeker
You passed [] for the angle argument for create_hitbox("was an array") a numeric value should be there instead ("REAL argument"). With languages that aren't static-typed, you have to pay attention to these details on your own.

The warning in the IDE means _hitbox is not being used anywhere else. If the code came from a tutorial, continue and pay attention to where it is used (the var tells me it's a later addition to the same piece of code). If it's your own devising and you don't need to use the created instance's ID later, just get rid of var _hitbox = part altogether. The presence of a return value doesn't imply that you have to store it.
 
M

MIWICP86

Guest
You passed [] for the angle argument for create_hitbox("was an array") a numeric value should be there instead ("REAL argument"). With languages that aren't static-typed, you have to pay attention to these details on your own.

The warning in the IDE means _hitbox is not being used anywhere else. If the code came from a tutorial, continue and pay attention to where it is used (the var tells me it's a later addition to the same piece of code). If it's your own devising and you don't need to use the created instance's ID later, just get rid of var _hitbox = part altogether. The presence of a return value doesn't imply that you have to store it.

Hey man, that worked a treat, thank you so much.
 
Top