Instance variables?

Non-platform specific questions.

Instance variables?

Postby Schprlock » Thu May 03, 2007 8:59 am

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...
Schprlock
 
Posts: 3
Joined: Wed Oct 04, 2006 1:54 pm
Score: 0 Give a positive score

Postby jazz_e_bob » Thu May 03, 2007 10:28 am

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...
Attachments
instance variables.zip
(14.28 KiB) Downloaded 129 times
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby jazz_e_bob » Thu May 03, 2007 10:33 am

Also.

Perhaps you have declared dir as a global variable instead of an actor variable...
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby Schprlock » Thu May 03, 2007 4:11 pm

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.
Schprlock
 
Posts: 3
Joined: Wed Oct 04, 2006 1:54 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest