Page 1 of 2

Set actor variable with a universal way

PostPosted: Sun Jul 29, 2007 5:30 pm
by Troodon
Hi,
Is there (I do hope there is because my game project depends on it) a way I can set an actor variable for example: health, for all clones of one actor?
Let's say I have 10 clones of one actor, when I use the code actorname.health = 100, it changes the health variable only for the first actor (actor.0). How can I change the data for all the clones at once?
Thanks

PostPosted: Sun Jul 29, 2007 6:36 pm
by Jay S.
Perhaps you could use a Draw Actor event for one of the clones? And don't use
Code: Select all
actorname.health=100;

but simply
Code: Select all
health=100;

Wouldn't this work? Usually when an event is modified in one actor, it affects all its clones... doesn't it? :(

PostPosted: Sun Jul 29, 2007 6:37 pm
by d-soldier
If that was in the Draw Actor event, the health would constantly be 100... You'll have to wait until one of the smart people to answer this one...

PostPosted: Sun Jul 29, 2007 6:43 pm
by Jay S.
d-soldier wrote:If that was in the Draw Actor event, the health would constantly be 100...

Oops, you're right. :shock:

I mean, use Create Actor instead... Then use Draw Actor and use ifs for actions to occur when health equals a given value.

PostPosted: Sun Jul 29, 2007 6:52 pm
by Troodon
I can't use just "health = 100" because that would affect only for the current actor (in what the script editor is). This is not enough for my project because the codes can't be added to the actors directly. For example I have one actor that makes a group of actors selected. In it I use:
Code: Select all
unit_A.select = 1;
unit_b.select = 1;
unit_c.select = 1;

This however affects only for the "original" actors (for example unit_a.0) but not for their clones (unit_a.1, unit_a.2, unit_a.3 etc).

PostPosted: Sun Jul 29, 2007 7:41 pm
by d-soldier
Oh, you could set a specific health variable for that actor and it's clones, so keep if global. So the create actor event (good if they are all created at the same time) would be

e1_health=100;

and the draw actor event would be the same:

if (e1_health<=0)
{
DestroyActor script here;
}

PostPosted: Sun Jul 29, 2007 7:50 pm
by Troodon
Nooooo
The clones can have different health values so I can't use it as global variable!

PS: What's that destroy actor thing? I'm not asking how to destroy my actor when they reach 0. I need just way to modify actor variable with all the clones when needed thank you.

Imagine the unit select example I gave in my earlier post. There is one key which can select all the units (when their select = 1). Of course the units can be also selected and deselected one by one.

My english isn't perfect to describe but I think you got what I mean.

Thanks for helping. :)

PostPosted: Sun Jul 29, 2007 8:02 pm
by Jay S.
tekdino wrote:The clones can have different health values so I can't use it as global variable!

OH, I didn't know that either, sorry! :( :)

PostPosted: Sun Jul 29, 2007 8:04 pm
by Troodon
No problem, I think I didn't explain very well in my first post. :)

PostPosted: Mon Jul 30, 2007 1:15 am
by DocRabbit
Try this demo out, click the button, will set 3 clones health to 100, leaving the other two at 0.

It uses the activation event tied to the three actors. The text actors are this code.

Code: Select all
textNumber=getclone("Seargent.0")->health;

and the other text actors respectively, only with incremented clonenames.
i.e.: Seargent.1, Seargent.2, etc.

The last clone gets its health directly from clones Seargent.1 and Seargent.2 with the following code in the draw actor event of Seargent.
Code: Select all
getclone("Seargent.4")->health=getclone("Seargent.1")->health + getclone("Seargent.2")->health;

You could use this method to give an overall health variable to a unit of 5 clones, and use a code like this to distribute it evenly across the unit members.
Code: Select all
getclone("UnitMember.1")->health=UnitHealth/5;
getclone("UnitMember.2")->health=UnitHealth/5;
...


Using the getclone2 code would really come in handy here I think, it is posted here somewhere, just do a search for it. It lets you specify the clonename and cloneindex, so you could setup a For Loop and shorten the code here.

Link to getclone2 post:
http://game-editor.com/forum/viewtopic. ... =getclone2

PostPosted: Mon Jul 30, 2007 2:34 am
by DilloDude
I would stor the clonename of each of my actors in an array. Then I can loop through the array to change properties.

PostPosted: Mon Jul 30, 2007 2:57 am
by Sgt. Sparky
all of those codes I have seen will not work if other actors got destroyed, there is a very simple solution, simply keep health as an actor varaible and make a global veriable called Set, next make an actor variable called sSet.
then:
put on the create actor event of you character
health = 100;
and on the draw actor event,
Code: Select all
if(health <= 0)DestroyActor("Event Actor");
if(Set == 1 && sSet == 0)
{
    sSet = 1;
    health = 100;
}

:D
you can take it from there.

PostPosted: Mon Jul 30, 2007 7:58 am
by Troodon
Thanks for the great help! :D
I managed to make it work with getclone.

PostPosted: Tue Jul 31, 2007 1:45 am
by Sgt. Sparky
tekdino wrote:Thanks for the great help! :D
I managed to make it work with getclone.

play the game for a while and it may mess up.(when not all of the clones are destroyed.) :(
I had this problem with cowboy jumper editor untill I changed some stuff with saving.

PostPosted: Tue Jul 31, 2007 5:21 pm
by Troodon
I think I know what you mean; I already ran accross some problems where some of the clones stopped reacting. I repaired it by creating 6 memory places for each actor type (max in the game is 5) so now there should be no risk of that problems anymore.
:)