• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

setting vspeed/hspeed upon instance_create

N

NeoIdea

Guest
Hey all!
So I have a few different spawning objects.
I would like to set a certain vspeed/hspeed for the instances created by the each of spawning objects.
For example an instance created with obj_spawner_a would have a vspeed of 1, but if that same object was instanced through obj_spawner_b, it would then have a speed of -1.

Here's what I have in alarm[0] for obj_spawner_a;


if instance_exists(obj_player){

instance_create(view_xview+random(view_wview),obj_player.y-450,obj_fast_asteroid);

alarm[0] = random(500);
}

So my question is, is there a simple/straight forward way of doing this from within the code I have in the alarm of the spawner_obj?
I figure I could go into the create event of each object and have something to the effect of;
if spawned through obj_spawner_a then vspeed = 1
if spawned through obj_spawner_b then vspeed = -1 and so forth.
Well, other than creating a variable... Is there a more obvious way I should know about?

Thanks you!
 
S

siggi

Guest
a=instance_create
a.speed=3278597346578329hjdfk

the instance_create function returns the specific id of the instance created, so you can set it as a variable and make further changes to it in the same chunk of code - hope this helps c:
 
T

tehguy

Guest
you can do the above or, I think, skip the having an extra var creation/assignment entirely with

Code:
with (instance_create(x,y,obj)){
    speed = 123456;
    //do more things if needed
}
placed in both spawners (assuming they are different objects) and modified as needed. You preference, as both should work
 
N

NeoIdea

Guest
Thanks, I'm going to give it a go in the morning. And let y'all know how it works out.
 
N

NeoIdea

Guest
you can do the above or, I think, skip the having an extra var creation/assignment entirely with

Code:
with (instance_create(x,y,obj)){
    speed = 123456;
    //do more things if needed
}
placed in both spawners (assuming they are different objects) and modified as needed. You preference, as both should work
Yeah, all the spawners spawn the same objects. I just want them to spawn the instances in different directions.
 
N

NeoIdea

Guest
So I just test it and it worked out. Thanks a lot guys!!!


if instance_exists(obj_player){

with(instance_create(view_xview+random(view_wview),obj_player.y-450,obj_fast_asteroid)){
vspeed = 4;



}}
alarm[0] = random(500);
 
G

Gillen82

Guest
Am I right in saying that you have 2 different spawners just to dictate the speed? And that both are creating instances of the same object? If so, would it not be easier just to have one spawner, then let the actual object dictate it's own speed? If so, you could go to the create event of the object and add the following (or similar):

Code:
randomize();

vspeed = choose ( -1, 1 );
This just means that when the object is spawned into the game, it will choose either 1 or -1 for its speed. You could also implement this to work for hspeed in the same way.

Sorry if I have misinterpreted your request :/
 
Top