Im trying to have the enemy object move right beside the player object, once he gets to a point before the player, I want the enemy object to stop everything its doing, play an attack animation and then continue. This is what I have so far (obj_amanda is the player object, obj_general is the enemy object):
Step Event:
if ((obj_general.direction < 70) or (obj_general.direction > 270))
{
sprite_index = spr_generalRight;
}
else if ((obj_general.direction > 70) or (obj_general.direction < 270))
{
sprite_index = spr_general;
}
if obj_amanda.x < obj_general.x
move_towards_point(spr_amanda.x + 60,spr_amanda.y + 20,3);
else if obj_amanda.x > obj_general.x
move_towards_point(spr_amanda.x - 60,spr_amanda.y + 20,3);
Animation End Event:
if ((obj_general.x = obj_amanda.x + 60) or (obj_general.x = obj_amanda.x - 60))
generalAttack = round(random(2));
if ((generalAttack = 0) and (obj_general.x = obj_amanda.x + 60))
sprite_index = spr_generalAttack2Left
else if ((generalAttack = 0) and (obj_general.x = obj_amanda.x - 60))
sprite_index = spr_generalAttack2
if ((generalAttack = 1) and (obj_general.x = obj_amanda.x + 60))
sprite_index = spr_generalAttack1
else if ((generalAttack = 1) and (obj_general.x = obj_amanda.x - 60))
sprite_index = spr_generalAttack1Right
The Animation end event is mainly there cause i didnt know where else to put this.
Temparaily Disable Step Event?
Started by kilokill, Aug 03 2012 08:04 PM
6 replies to this topic
#1
Posted 03 August 2012 - 08:04 PM
#2
Posted 03 August 2012 - 08:24 PM
Temporarily "disabling" the event shouldn't be too hard
Create:
Step:
Whenever you want to disable the step event:
Create:
StepActive = true;
Step:
if (StepActive)
{
//Step code here
}Whenever you want to disable the step event:
StepActive = false;
#3
Posted 03 August 2012 - 08:29 PM
You can "disable" a step event by using a variable like "disabled". Set it to false in Create. Then, in the beginning of the step event:
I noticed some points about your code:
1) You don't need separate sprites to make the right and left attacks/movements. Simply use image_xscale variable.
2)round(random(2)) will sometimes return '2', which will result in no attack to be used. This happens when the random functions returns a value that's higher than 1.5. Try floor(random(2)) instead. This will always round the result down.
3) If you have multiple enemies, you can just write "x" instead of "obj_general.x". This way, you'll always use the local x coordinate of that particular general object.
if disabled exit
I noticed some points about your code:
1) You don't need separate sprites to make the right and left attacks/movements. Simply use image_xscale variable.
image_xscale = -1will mirror the sprite horizontally. If you're using the draw event for the character, you will have to use draw_sprite_ext for image_xscale to take effect.
2)round(random(2)) will sometimes return '2', which will result in no attack to be used. This happens when the random functions returns a value that's higher than 1.5. Try floor(random(2)) instead. This will always round the result down.
3) If you have multiple enemies, you can just write "x" instead of "obj_general.x". This way, you'll always use the local x coordinate of that particular general object.
#4
Posted 03 August 2012 - 08:54 PM
So its now looks like this:
Create Event:
image_speed = .1
globalvar generalAttack;
globalvar StepActive;
StepActive = true;
Step Event:
if (StepActive = false)
exit
if ((obj_general.direction < 70) or (obj_general.direction > 270))
{
sprite_index = spr_generalRight;
}
else if ((obj_general.direction > 70) or (obj_general.direction < 270))
{
sprite_index = spr_general;
}
if obj_amanda.x < obj_general.x
move_towards_point(spr_amanda.x + 60,spr_amanda.y + 20,3);
else if obj_amanda.x > obj_general.x
move_towards_point(spr_amanda.x - 60,spr_amanda.y + 20,3);
End step:
if ((obj_general.x = obj_amanda.x + 60) or (obj_general.x = obj_amanda.x - 60))
StepActive = False;
generalAttack = floor(random(2));
if ((generalAttack = 0) and (obj_general.x = obj_amanda.x + 60))
sprite_index = spr_generalAttack2Left
else if ((generalAttack = 0) and (obj_general.x = obj_amanda.x - 60))
sprite_index = spr_generalAttack2
if ((generalAttack = 1) and (obj_general.x = obj_amanda.x + 60))
sprite_index = spr_generalAttack1
else if ((generalAttack = 1) and (obj_general.x = obj_amanda.x - 60))
sprite_index = spr_generalAttack1Right
Once obj_general gets to obj_amanda.x +60 or -60 general just keeps spazzing at the point, the step event isnt disabling, I cant see what ive done wrong. Thanks for the responses so far guys.
Create Event:
image_speed = .1
globalvar generalAttack;
globalvar StepActive;
StepActive = true;
Step Event:
if (StepActive = false)
exit
if ((obj_general.direction < 70) or (obj_general.direction > 270))
{
sprite_index = spr_generalRight;
}
else if ((obj_general.direction > 70) or (obj_general.direction < 270))
{
sprite_index = spr_general;
}
if obj_amanda.x < obj_general.x
move_towards_point(spr_amanda.x + 60,spr_amanda.y + 20,3);
else if obj_amanda.x > obj_general.x
move_towards_point(spr_amanda.x - 60,spr_amanda.y + 20,3);
End step:
if ((obj_general.x = obj_amanda.x + 60) or (obj_general.x = obj_amanda.x - 60))
StepActive = False;
generalAttack = floor(random(2));
if ((generalAttack = 0) and (obj_general.x = obj_amanda.x + 60))
sprite_index = spr_generalAttack2Left
else if ((generalAttack = 0) and (obj_general.x = obj_amanda.x - 60))
sprite_index = spr_generalAttack2
if ((generalAttack = 1) and (obj_general.x = obj_amanda.x + 60))
sprite_index = spr_generalAttack1
else if ((generalAttack = 1) and (obj_general.x = obj_amanda.x - 60))
sprite_index = spr_generalAttack1Right
Once obj_general gets to obj_amanda.x +60 or -60 general just keeps spazzing at the point, the step event isnt disabling, I cant see what ive done wrong. Thanks for the responses so far guys.
#5
Posted 03 August 2012 - 09:00 PM
Why did you make it global? I thought it needed to be disabled on a per-instance basis. Oh well, run in debug mode, add watch expression and type StepActive. 1 is true and 0 is false.
#6
Posted 03 August 2012 - 09:08 PM
For some reason when I dont have it set as global var, i get crash saying it isnt a variable.
#7
Posted 03 August 2012 - 09:10 PM
Well, I'm not sure what you're doing, but you'd likely need obj_amanda.StepActive, or obj_player.StepActive, or whatever object you're working with.
Edited by Big J, 03 August 2012 - 09:10 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











