Now take a look at this: download/file.php?id=66
download it and fire it up.
First glance at the event. Wah ? Thats like 1/7th compared to the .cap in previous post.
Yes sir, that what Instances are designed for.
But lets start in the layout editor.
The preparations for this project.
I only had to add 1 object to the layout. (yes the selector also, blah)
An instance you make by just copy and past. Thats it.
But i made those instances by,
selecting the first added object, right click it, choose "array past" from the contextual menu.
Its 1D, 7 count.
in the move X i filled the value 60.
and i pressed ok.
And that takes 5 seconds to do.
Because they are instances of the same object.
Adding a private variable has to be done only once on 1 of the objects.
Adding a behavior has to be done only once on 1 of the objects.
Not 7 times !
And if you do this before making the instances, also the private variables initial values,
and all the behavior properties will be exact the same in the copys.
Again this 1/7th of the time to manage this. With 1/7th less chance on errors.
In the events editor.
Event 2 is a special advanced Loop.
the "for each object ordered" loop that can be found in the system conditions.
It runs trough all instances of the Bug,
picks them one by one, here starting with the lowest X,
and feeds the picked objects to its sub events and actions.
So the action to deactivate the behavior we only have to put once.
Storing the start X and Y we only have to do once.
At same time we give the instances a identification number, to be able to pick them by comparing the private variable thats holding the value with the identification number.
The private variable = 'My_number_is"
The value we give it can be found in the system expressions = current loopindex
The instance with the lowest X gets number 1. The next one get 2 .. and so on.
In event 3 we initialize the global variables used for Flow.
in event 4 we set the behavior of the first instance to active.
This is a pick condition. It can be find in any objects conditions as "compare private variable".
What it actual do is:
It picks all instances of the object Bug...
Runs trough the private variable thats given as parameter,
and when the condition is true, here when "My_number_is" = 1,
it will set that object as picked.
So on our case, it picks out the first instance of the bug,
and the action sets the behavior of that Bug to active.
In event 5 and 6
We add or subtract from the global variable 'selected' according the key thats hit.
We have 7 objects, so if the variable gets out the range of 7, we make it loop back/forth
Dont matter how many times u hit the arrow keys, 'selected' will be in between 1 to 7.
Now we have only 2 conditions.
Condition 1: Its "My_number_is" is the same as 'selected'.
In that case the selector must jump to this objects position,
its behavior must be active, and thats it !!!
Condition 2: Its "My_number_is" not the same as 'selected'.
In this case the objects behavior has to be deactivated,
and the object needs to be placed at its starting position
Now the global variable 'select' is not really needed. Its just one of my style elements.
If i dont use it, the 2 conditions will run every tick.
And every tick (by example) the behavior gets activated, because there will always be 1 object selected.
I dont like to spend so much CPU cycles to do only this.
When you hit the arrow key to select another bug, the variable 'select' gets set to "M",
the M from Mark.
When its "M" the 2 conditions run. Directly after they did there work,
'select' gets set to "X", X for crossed out.
The 2 conditions will now not run till hitting an arrow key brings 'select' back to "M"
Of course, explaining all this takes more time then actual make this. I made it in 10 minutes.
Plz, do not ask me how much time i took to make the .cap in previous post.
Now, do you see the power of instances ?