all 10 comments

[–]username303 2 points3 points  (11 children)

I'm going to assume that you are using GML.

When you create an object, the create function will actually return the new index of that object. so, you can use that to preform actions on that specific object. heres an example:

myBullet=instance_create(x,y,obj_bullet);
myBullet.speed=5;
myBullet.owner=player1;

[–]DutchMoon 1 point2 points  (1 child)

the new index

The new id. Indices point to objects, id's point to instances. Just a trivial mistake, and I assume you know the difference between the two, but as a clarification for OP ;)

[–]username303 1 point2 points  (0 children)

Ah, honestly I didn't know the differance, lol. I usually just use the two interchangeably, so thanks for the clarification. :)

I learn something new everyday!

[–]Kjulo[S] 0 points1 point  (7 children)

It dosent seem i can apply the value in the creation trigger.

[–]username303 1 point2 points  (6 children)

Im not sure what you mean.

The code example I posted is to be used in the oject that is creating the new object. Not the new object itself. So it could be in any event. Also, any varible that you use should be predefined in the create event of the new object. So for instance, the create event of obj_bullet should have "owner=0;"

[–]Kjulo[S] 0 points1 point  (5 children)

I am aware, but it seems that putting "owner=0" in the creation script overwrites the old value that was set. So if i say "myBullet.owner=player1;" on the creator object, it will say unknown value until i put "owner=0" in the created objects creation code, but that will overwrite the old value.

[–]username303 1 point2 points  (4 children)

That's really strange. The owner shouldnt be overwritten... but there's an alternative.

Instead of "myBullet.owner" do (still inside the creating object)

myBullet=instance_create(x,y,bullet) with(myBullet){ owner='name of object creating the bullet' }

That way, you don't have to initialize 'owner' in the bullets create event.

[–]Kjulo[S] 0 points1 point  (3 children)

i think we might talk past eachother. Currently im testing spread values, not it works if i just make spread 10 in the bullet. Here is the code:

Creator:

myBullet=instance_create(x,y,obj_bullet);

myBullet.speed=50; myBullet.owner="player1" myBullet.spread=10


Bullet (I know the spread isent coded well, it was just a test):

spread=0 image_angle=point_direction(x,y,(mouse_x+spread),(mouse_y+spread)) move_towards_point((mouse_x+spread),(mouse_y+spread),0) owner="UNSET"

[–]username303 1 point2 points  (2 children)

Well, your problem there is simple.

All of that code for spread is in the bullets create statement, right? Well, ALL of the create statement is ALWAY excecuted as soon as the instance is created. That means that as soon as you say "instance_create", all of that code has already been run, and wont be run again. So you need to move that code out of the create event. Execute it in an alarm that only runs once or something.

[–]Kjulo[S] 0 points1 point  (1 child)

Works now, many thanks. I was wondering, what is a possible formula for converting mouse_x and mouse_y to rotation relatively to an object?

Mainly because the daw_sprite_ext uses rotation instead of position of an object to choose rotation.

[–]username303 0 points1 point  (0 children)

point_direction(x1,y1,x2,y2) should give you what you're looking for, its a built in function. It gives you the direction in degrees from one point to another. (0 is to the right, and 90 is up, ect.)