Jump to content


Photo

Newest Instances


  • Please log in to reply
2 replies to this topic

#1 y6t75r9f2

y6t75r9f2

    GMC Member

  • New Member
  • 2 posts
  • Version:GM8

Posted 09 March 2012 - 10:44 PM

I made an object that shows up on screen, waits a short while, then shoots a circle of bullets. It works, but when I put two of them on screen together, it messes up. I created the objects with code because I needed to synch it with a timeline and also needed to set variables depending on when it was used for re-usability. What I mean by that is I want the 'short while' before the object shoots to be in time with the music, and since different levels have different music with different BPM, I set the delay after I declare it. I know about the 'with' structure, and I can get both to shoot WHEN it is supposed to, but the second one doesn't shoot a full circle. My code for shooting in a circle was a for loop where x goes from 0 to 360, and I used motion_set(test.x,speed). The first one shoots fine, but the second only shoots straight to the right, probably because test.x is pointing to the first 'test's x variable. I can't remove the first one because the object has to be killed by the player first, so is there some way I can only reference the newest instance of an object?

EDIT: I solved it. In the last block of code I posted for shooting, I changed 'TimeTest.f' into 'other.f'. Boy do I feel stupid now

Edited by y6t75r9f2, 10 March 2012 - 07:56 PM.

  • 0

#2 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16839 posts
  • Version:GM:Studio

Posted 09 March 2012 - 10:48 PM

Could you post the actual code? How you create the instances as well as how they shoot, please!
  • 0

#3 y6t75r9f2

y6t75r9f2

    GMC Member

  • New Member
  • 2 posts
  • Version:GM8

Posted 09 March 2012 - 11:06 PM

Could you post the actual code? How you create the instances as well as how they shoot, please!


Well I created the instance with DnD in the timeline, and right after I put
with TimeTest{
if(New!=0){
    image_index=1
    image_speed=0
    Wave=2
    NewDelay=20
    alarm[11]=NewDelay
}
}

Wave is how many circles it shoots, and NewDelay is steps until the variable New in the object is turned to 0, in which case its actions cannot be modified anymore, hence the if condition to be 'if not new'. A few steps later in the timeline, I have this:

with TimeTest{
if(New!=0){
    alarm[0]=12
    Delay = 12
    image_index=0
    image_speed=0
}
}

for all the TimeTest(the circle shooter, sorry I didn't mention earlier) instances, it sets alarm 0 to 12, which is in this case timed with the music. Image index is changed to give a warning to the player. Delay is the steps between circle waves shot(Wave from first code block). Alarm 0 shoots the circle with this code, if wave is greater than 1:

for(f=0;f<360;f+=5){
    with instance_create(x,y,EnemyShot)
    motion_set(TimeTest.f,8)
}

Then it lowers Wave by 1 and calls itself again.

I made 2 objects appear, one about 50 steps later than the first, and both shoot twice 12 steps after (I drew the values on screen). I also drew both objects their corresponding 'New' variables, and they were '1' when they needed to be, and '0' after the 20 steps I declared it to be. The 50 steps allowed the first object to finish 2 perfect waves, and soon after the second one showed up. It changed to the warning colour without changing the first one, and it fired without making the first one fire, but it only shot straight to the right

Edited by y6t75r9f2, 09 March 2012 - 11:13 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users