Page 1 of 1

Instance variables?

PostPosted: Thu May 03, 2007 8:59 am
by Schprlock
Hi,

I am trying to create different clones of the same actor and add different variable values to them, but it turns out that all variables seem to be static.
For example, on an actors Create Event I want to set a direction variable to a random number with dir=floor(rand(4)), but if I create 10 different actors they all get the same dir as the one created. Same goes to actor variables like x and y.

Also, how can I access the x coordinate, for example, for an actor instance? What I mean is, enemy.0.x does not work...

PostPosted: Thu May 03, 2007 10:28 am
by jazz_e_bob
You can set your clones variables as they are created.

For example

On Create Character

Code: Select all
x = rand(100) - 50;
y = rand(100) - 50;

myDirection = rand(360);

angle = myDirection;
directional_velocity = 3;


Each clone will have its own random position and direction.

OR

If your actors are being created by another actor you can use:

On Mouse Down clickMe

Code: Select all
Actor *newBullet = CreateActor("bullet", "icon", "(none)", "(none)", 0, 0, false);

newBullet->yvelocity = -(rand(10) + 10);


See demo attached...

PostPosted: Thu May 03, 2007 10:33 am
by jazz_e_bob
Also.

Perhaps you have declared dir as a global variable instead of an actor variable...

PostPosted: Thu May 03, 2007 4:11 pm
by Schprlock
Your're absolutely right... I don't know what I was doing wrong, because now it worked just fine (with x and y, I didn't have time to try changing the variable dir). No, dir was an actor variable... I'll find out.

Thanks a lot for your help.