Changing an attribute for all instances of an actor

rm2kmaster

  • Posts: 3
Hi Guys

I'm working through the tasks at the end of the crash course 2 tutorial and i'd like it if that every time one of the enemy space ships died, the rest would speed up by a certain amount. However I only seem to be able to edit the 'speed' attribute for a a single enemy at a time.
For example: In the 'death' event for the enemy I have put "increment 'speed' by 10" before "kill self". This obviously only affects the ship that the event is running on.
I've also tried imputting a "for each actor of type: enemy ship" block  in before the increment (see attachment)but this doesn't seem to work either...
I assume i'd need some kind of attribute type that spans all instances of an actor...?
I really thought I was starting to get on a roll when i'd gotten them to move but this has brought me to a real stop!

Thanks

Natrium

  • *
  • Posts: 110
For each actor of type is the way to go, but you need to use the blocks shown in this thread to change an attribute belonging to another actor. Click on the small arrow in the empty spaces of the block to choose the attribute and the behavior name.

« Last Edit: July 28, 2015, 01:47:28 pm by Natrium »

rm2kmaster

  • Posts: 3
Thanks.
I'm still not as far as behaviors yet so i've no idea how they work - do they have to be referenced to be able to edit an attribute for another actor?

EDIT: Never mind - figured it out! Thanks very much for your help!

« Last Edit: July 28, 2015, 03:20:11 pm by rm2kmaster »

Natrium

  • *
  • Posts: 110
You're welcome!

I thought about an other way to do it, maybe you'll find it easier: you trigger an event (say, "IncreaseSpeed") in all behaviors for every actors of the enemy type. Then you make it so that the IncreaseSpeed event of the enemy increments its speed. That would work to, but may be more convoluted.

rm2kmaster

  • Posts: 3
Ran into another conundrum
Currently, my enemies from one side of the screen to the other, and when one dies, the rest speed up.
The issue with this is that a speed update is only run once one of the sides is hit and it "sets x-speed to [enemy speed] for self"
Is there anyway to make it so that the x-speed is constantly mirrored with the enemy speed variable so that the speed of the enemy updates as soon as another enemy dies?

This is a small thing, not too worried if a solution is a bit too out of my skill range at the moment!

I've never really had any deailing with code before, figuring out solutions to problems is one of the most satisfying feelings i've ever had!

Natrium

  • *
  • Posts: 110
I'm not sure if I understand correctly, but you could just put a set x-speed block just after changing the speed attribute in the for each... block. You would have to check whether the current speed is positive or negative in order to apply the new speed in the right direction.