Set actor variable with a universal way

Non-platform specific questions.

Set actor variable with a universal way

Postby Troodon » Sun Jul 29, 2007 5:30 pm

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
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby Jay S. » Sun Jul 29, 2007 6:36 pm

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? :(
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby d-soldier » Sun Jul 29, 2007 6:37 pm

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...
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby Jay S. » Sun Jul 29, 2007 6:43 pm

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.
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby Troodon » Sun Jul 29, 2007 6:52 pm

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).
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby d-soldier » Sun Jul 29, 2007 7:41 pm

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;
}
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby Troodon » Sun Jul 29, 2007 7:50 pm

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. :)
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby Jay S. » Sun Jul 29, 2007 8:02 pm

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! :( :)
User avatar
Jay S.
 
Posts: 118
Joined: Thu Apr 26, 2007 6:51 pm
Location: My computer desk. :P
Score: 9 Give a positive score

Postby Troodon » Sun Jul 29, 2007 8:04 pm

No problem, I think I didn't explain very well in my first post. :)
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby DocRabbit » Mon Jul 30, 2007 1:15 am

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
Attachments
IndividualHealthDemo.zip
Example Demo
(203.4 KiB) Downloaded 119 times
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score

Postby DilloDude » Mon Jul 30, 2007 2:34 am

I would stor the clonename of each of my actors in an array. Then I can loop through the array to change properties.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Sgt. Sparky » Mon Jul 30, 2007 2:57 am

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.
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Troodon » Mon Jul 30, 2007 7:58 am

Thanks for the great help! :D
I managed to make it work with getclone.
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby Sgt. Sparky » Tue Jul 31, 2007 1:45 am

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.
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Troodon » Tue Jul 31, 2007 5:21 pm

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.
:)
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron