Setting the variable of an object as its created
#1
Posted 09 April 2011 - 05:30 AM
So I was wondering, how do I program it so that when the gun object creates the bullet it also sets the velocity/stopping power of the bullet? I will be using several different guns with different levels of power but i am hoping that i could use the same bullet object but just have it so that it is created with a different starting value for the velocity variable depending on what gun the character has equipped, if that makes sense.
it can't be
{
instance_create(x,y,obj_bullet)
obj_bullet.var_velocity=1337
}
because that would make all the bullets in the room have 1337 velocity.
All help is appreciated, sorry for my noobish and probably very unclear question, since i am very very tired right now lols.
#2
Posted 09 April 2011 - 05:41 AM
instance_create(x,y,obj_bullet);
with(obj_bullet) var_velocity=1337;
}
or
{
instance_create(x,y,obj_bullet);
with(other) object_bullet.var_velocity=1337;
}
I am not sure but giving it at least a try is a good idea.
#3
Posted 09 April 2011 - 05:45 AM
#4
Posted 09 April 2011 - 06:04 AM
I'm making a zombie shooter type game and one feature of it will be a heavy focus on bullet penetration. I plan to have it so that if you shoot a zombie with a high powered weapon, depending on which kind, the bullet will not just stop in a zombie's dome but it will come out the other end of it's skull and continue to travel through the air until it hits enough material to slow it down enough to stop.
So I was wondering, how do I program it so that when the gun object creates the bullet it also sets the velocity/stopping power of the bullet? I will be using several different guns with different levels of power but i am hoping that i could use the same bullet object but just have it so that it is created with a different starting value for the velocity variable depending on what gun the character has equipped, if that makes sense.
it can't be
{
instance_create(x,y,obj_bullet)
obj_bullet.var_velocity=1337
}
because that would make all the bullets in the room have 1337 velocity.
All help is appreciated, sorry for my noobish and probably very unclear question, since i am very very tired right now lols.
(instance_create(x,y,obj_bullet)).var_velocity=1337;
or
with (instance_create(x,y,obj_bullet)){
var_velocity=1337;
//Plus any other variables you want
}
Keep in mind that if you create a variable in this manner you cant then go into that object and alter that same variable in the create event. It has to happen sometime after the create event.
So like if you wanted var_velocity+=10 to happen in the create event but also be created with the code above, you'd have to set an alarm or use some other mechanism outside of the create event.
Edited by joethedumblr, 09 April 2011 - 06:07 AM.
#5
Posted 09 April 2011 - 06:06 AM
assign a variable to the instance
varible=instance_create(x,y,lolbullet)
variable.stuff = a number
#6
Posted 09 April 2011 - 06:31 AM
oh hi thar food
assign a variable to the instance
varible=instance_create(x,y,lolbullet)
variable.stuff = a number
fawful, i missed your ****chalking pickleflutage bro : )
but, wouldn't this script change the variable of all lolbullets to that number? :C
and @joethedumblr I used
with (instance_create(x,y,obj_bullet)){
var_velocity=1337;
//Plus any other variables you want
}
and it worked great
@Everybody: thank you all for your help
#7
Posted 09 April 2011 - 01:12 PM
but, wouldn't this script change the variable of all lolbullets to that number? :C
No, it wouldn't, because the return variable contains a ID of a specific instance, so it will only affect that instance and leave everything else alone.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











