Fangames > Programming Questions
Spawning attack by player x and set y?
(1/1)
Hop:
So I am trying to create a boss attack that spawns a sword that shoots up out of the ground and then goes back down. I want it to spawn under the players current position and along the y access of the floor. So I set up an alarm that calls it like so.
if (instance_exists(objPlayer))
{
var a = instance_create(player.x,y,objGLSword);
alarm[0] = 100;
}
I'm not sure what to put for the y to make it at ground level and the game just crashes whenever the alarm goes off.
In the objGLSword object I just have the image speed set and then it deletes after animation end.
The crash report reads:
Fatal error in action number 1 of alarm event for alarm 3 for object objBoss
Push :: Execution Error - Variable Get 103930.player(100162, -2147483648)
at gml_objBoss_objAlarm3_1(line 3)- var a = instance_create(player.x,y,objGLSword);
Also how would I make it so the attack would only go off 5 or so times and then the alarm would stop resetting?
PS: I'm using yoyo's studio engine.
lawatson:
woopsies! there's a typo. in the instance_create, you accidentally put player.x instead of objPlayer.x
typos can get you, man!
P.S. any variables which are defined with var; code will disappear after the code ends, but if you drop the var; part and just define the variable then it'll stay permanent throughout the object.
P.S.S. making it happen 5 times can be done with a variable.
In the create event: amount=0;
In the alarm event:
if amount<5{
amount+=1;
alarm[0]=100;
if instance_exists(objPlayer){
var a = instance_create(objPlayer.x,y,objGLSword);
}
}
and whenever you want the attack to happen again, just reset amount to 0.
Aelya:
y should be close to the room height, of course :p so 608 or a little more (so it actually spawns from below the room)
Hop:
Thanks guys it works great now!
Navigation
[0] Message Index
Go to full version