Page 1 of 1

Setting velocity to all clones

PostPosted: Mon Sep 30, 2013 9:32 pm
by gustavo02
I'm still a beginner so maybe this is something very easy but I don't know how to fix. I took a look at some topics about clones but I couldn't understand many things, and what I could understand didn't help me. Here is what I did:


At the beginning of me game there is a buttom the executes the following code when you click it:
Code: Select all
//This destroys the button I just used
DestroyActor("BotaoOb1");

//This creates a new start button
CreateActor("ob1start", "start", "(none)", "(none)", 400, 150, true);

//This is where I create many copies of the same actor, called "ob1vermelha", in different places on the screen. Those actors are balls.
CreateActor("ob1vermelha", "ob1 bola vermelha", "(none)", "(none)", -400, -200, true);
CreateActor("ob1vermelha", "ob1 bola vermelha", "(none)", "(none)", -350, -200, true);


So now I have a start button and many balls on the screen (in this case, just two). Everything is motionless. Like this:
http://img534.imageshack.us/img534/3900/k7oa.jpg

But what I want is to command all the balls to start moving only when I press the Start Button (ob1start). So I added a Mouse Button Down event to this start button, and used the script editor like this:
Code: Select all
ob1vermelha.xvelocity = +2;

This works fine for me when I'm dealing with different actors, because I only need to add this kind of commands to each one in the same script. But in this case, because I created two copies of the same actor on the screen, only the first one moves, and the other remains still. Like I said, I'm a beginner so I don't even know if what I did is the same as creating clones.

But most importantly, is there a command to make all those copies move at once? (I don't mind if the velocity of them all is the same or is different, I just need all of them to move when I press the button).

Here is a copy of the ged file:
http://depositfiles.org/files/aivck0zh1

Thanks

Re: Setting velocity to all clones

PostPosted: Tue Oct 01, 2013 7:41 pm
by skydereign
There currently isn't an easy way to tell all clones to do something. But this solution may work for you. You can give code to all the clones to make them move in their create actor. That way they will all be moving when they are created. Now you specified you wanted them to move only when that button is clicked, so if that is actually the case, then you can do this.
Code: Select all
if(start_button.cloneindex!=-1) // if the start button still exists
{
    xvelocity = -2;
}

This will work if you destroy the button after you create the ob1vermelha actors. One note, you have DestroyActor("BotaoOb1"), you should just use DestroyActor("Event Actor") if you want to target the actor that was just clicked. You should always use "Event Actor" when you want to change the actor that is currently executing the event. For the same reason using ob1vermelha.variable doesn't work.

Re: Setting velocity to all clones

PostPosted: Wed Oct 02, 2013 1:37 am
by gustavo02
Thanks! It seems I really need to study scripts. But today I came with a quite simple solution for my problem:

I made 2 different actors, I'll call it ballA and ballB here. They have the same animation, so they look the same. But ballA has no events and does nothing, it is just motionless. ballB has a "Create Actor" event that sets its xvelocity to 3 (for example).

The first button creates many clones of ballA on the screen. Since ballA does nothing, I can stare at the motionless balls all the time I want. The second button, the start button, destroys all ballA and creates ballB in the exact same place. Since ballB has that "Create Actor event" that sets its velocity to 3, it will move. When I do this the impression we have is that the same balls that were still are now moving. (It seems to work so far, at least.) = ]

Now I can also create some ballC, set a different velocity to it and put them in the place of some ballA, so I'll have something like group of balls moving in specific ways.

(Before this method, I could make it work using the Enable and Disable Events function too, but it was more confusing and didn't work that good.)