Page 1 of 1

Actor variable

PostPosted: Thu Oct 20, 2011 4:55 pm
by Agusstosus15
how to change declared Actor variable?

Re: Actor variable

PostPosted: Thu Oct 20, 2011 6:30 pm
by Hblade
what do you mean?

Code: Select all
MyActor.actorvariable=5;


If you want to manually declare an actor variable you need an array.
Code: Select all
short int ActorVar1[65535];


Then you'd want to define actornames to the variable
Code: Select all
#define _Player ActarVar1[0]
#define _Enemy1 ActorVar1[1]


And so fourth. but this will not work with clones or new-created actors unless you script something insane.

Re: Actor variable

PostPosted: Thu Oct 20, 2011 7:57 pm
by savvy
yeah, basically if you are editing an actor variable in the actor you want to change just use
Code: Select all
variable = 0;

or whatever number...
if your editing another actors actor variable use
Code: Select all
actor.variable=0;

this is what Hblade said, i am merely trying to make it seem more simple :D

savvy

Re: Actor variable

PostPosted: Thu Oct 20, 2011 8:26 pm
by Agusstosus15
int i;
postac_rycerz_pion.sila=+1;

i=getclone ("postac_rycerz_pion.0")->sila;

if (i>3)
{
DestroyActor("Event Actor");
}

sila is Actor variable extended it's structure i declared in variable bar in script editor
what's wrong with code?

Re: Actor variable

PostPosted: Thu Oct 20, 2011 9:29 pm
by EvanBlack
Well.. there doesn't appear to be anything wrong with it just by looking at this small piece. More information is needed to know where this code is and how its being called.

By looking it appears to be in an event but the thing is, it looks like every time this is called after the third time it destroys the actor which holds this event..

If you have 3 actors with this event, and all 3 actors call this event 1 time, then all actors with this event will be destroyed. Any actors created after that call this event will also be destroyed.

In the event that postac_rycerz_pion.0 is destroyed, you will most likely get a reference to a NULL pointer or just a read error. if this is called anywhere after postac_rycerz_pion.0 is destroyed. But because getclone returns a null actor, i just might always = 0 after postac_rycerz_pion.0 is destroyed so any actors calling this even even if there is an actor postac_rycerz_pion.1 which sila will keep increasing by 1 postac_rycerz_pion.0 doesn't exist so i is always less than 3 so DestroyActor() never gets called.


Thats everything I can say about this segment of code.

Re: Actor variable

PostPosted: Thu Oct 20, 2011 9:48 pm
by skydereign
Your code is using =+, instead of +=. If you wanted to change sila, then you need to use +=. Otherwise you are just setting sila to 1.
Code: Select all
int i;
postac_rycerz_pion.sila+=1;

i=getclone ("postac_rycerz_pion.0")->sila;

if (i>3)
{
    DestroyActor("Event Actor");
}

Re: Actor variable

PostPosted: Thu Oct 20, 2011 10:22 pm
by Agusstosus15
thanks black I know already that :)
thanks sky , that was it += :)

big thanks for both of you

sila is different for any actor in game, right?

Re: Actor variable

PostPosted: Thu Oct 20, 2011 11:42 pm
by EvanBlack
with the code you are using it changes sila of all the actors with that name, if you want to change one actor clone then you have to use get clone and have it reference the variable.

Code: Select all
getclone ("postac_rycerz_pion.0")->sila += 1; // This changes postac_rycerz_pion.0's sila variable only



There are a couple of ways to get the clone or actor you want. The easiest method depends on what is calling the function and which clone you want to access.

Re: Actor variable

PostPosted: Fri Oct 21, 2011 12:18 am
by Agusstosus15
but only actors with that name, god thanks :)
ok I got it, thank you once again
night for me
day for you
see ya:)

Re: Actor variable

PostPosted: Fri Oct 21, 2011 12:20 am
by skydereign
Using actorname.actorvar does not change every clone of actorname's variable. It uses the default struct, so normally the lowest indexed clone. If you just created a clone in the event, it will use the newly created actor. So using getclone and the Actor* is the same as using the struct directly if you use getclone to access the lowest clone.
Code: Select all
actor.r=0; // sets the r of the clone with the lowest cloneindex
CreateActor("actor", "icon", "(none)", "(none)", 0, 0, false);
actor.r=0; // sets the newly created actor's r to 0