Author Topic: Spawning attack by player x and set y?  (Read 1958 times)

Hop

  • Wannabe
  • Posts: 43
  • HopPros on Twitch
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Spawning attack by player x and set y?
« on: December 31, 2015, 02:01:07 AM »
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

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.80 Chrome 47.0.2526.80
    • View Profile
  • Playstyle: Keyboard
Re: Spawning attack by player x and set y?
« Reply #1 on: December 31, 2015, 03:29:26 AM »
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.
« Last Edit: December 31, 2015, 03:39:48 AM by lawatson »
(click to show/hide)

smoke weed everyday

Aelya

  • Cherry Eater
  • Posts: 55
  • love~ <3
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
    • stream
  • Playstyle: Keyboard
Re: Spawning attack by player x and set y?
« Reply #2 on: December 31, 2015, 06:30:07 AM »
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

  • Wannabe
  • Posts: 43
  • HopPros on Twitch
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Spawning attack by player x and set y?
« Reply #3 on: January 03, 2016, 02:24:07 PM »
Thanks guys it works great now!