ID:265019
 
Code:
obj
var
countdown=10
direction
Boom_Bullet
icon='Bullets.dmi'
icon_state="Boomer"
New()
while(countdown)
countdown--
step(src,SOUTH)
sleep(0.5)
var/obj/Pellet/P = new()
P.loc=locate(src.x,src.y,src.z)
P.direction=WEST
del(src)
Pellet
icon='Bullets.dmi'
icon_state="Pellet"
New()
walk(src,src.direction)
spawn(5) del(src)


Problem description:

Basically, I want to make a bullet that travels downwards for a short time, then disappears; leaving behind a different bullet that travels westward. Everything works fine except I'm having problems getting the bullet to actually move..Any help would be lovely

Thanks in advance
@ first glance it looks fine to me?
Do you have something else preventing/governing movement?
Such as and obj/Move() proc?

Side note:
I was of the understanding that BYOND couldnt interpret sleep(0.5) and rounded it to sleep(1)?? Interested to know otherwise.
TBH could test it but CBF.
In response to Saucepan Man
Saucepan Man wrote:
@ first glance it looks fine to me?
Do you have something else preventing/governing movement?
Such as and obj/Move() proc?

Not that I know of..I've directly set it to WEST to see if it works like that, and it does; but I'm thinking the problem might be that it tries to move before it has a direction. Though, I honestly can't think of a way to fix it :T.

Side note:
I was of the understanding that BYOND couldnt interpret sleep(0.5) and rounded it to sleep(1)?? Interested to know otherwise.
TBH could test it but CBF.

Hah, I haven't a clue. That's definitely something to think about, though.
At first glance everything might function properly, except you seem to be missing the parent proc "..()", which causes the procedure to do what it would originally do. For example, calling New() means you need to call "..()" or else New() won't do what it's expected to do.

Also the variable for direction seemed unnecessary, since there's already a predefined variable for that!

obj
var
countdown=10
//direction (unnecessary)
Boom_Bullet
icon='Bullets.dmi'
icon_state="Boomer"
New()
..() //here
while(countdown)
countdown--
step(src,SOUTH)
sleep(0.5)
var/obj/Pellet/P = new()
P.loc=locate(src.x,src.y,src.z)
P.dir=WEST //instead of direction, just use the predefined direction
del(src)
Pellet
icon='Bullets.dmi'
icon_state="Pellet"
New()
..() //and here
walk(src,src.dir)
spawn(5) del(src)
In response to Speedro
There's a predefined var for counting down??
In response to Saucepan Man
errr...

*Looks back at previous post and copy pastes:*

"Also the variable for direction seemed unnecessary, since there's already a predefined variable for that!"


There's a predefined variable for direction, not countdown.
In response to Speedro
Thanks a million for the help, but there's one more problem. Everything seems to work, except that it travels south instead of west. Like I told Saucepan Man, I believe it's moving before it's direction is set, so it walks south(which I'm assuming is the default dir)
In response to Speedro
lolzenge. My bad
In response to Gravity Sandwich
try typing direction here:
new(direction=WEST)
In response to Gravity Sandwich
Ah yup well what's going on is that the object is created, and the proc "New()" is run before the direction is set.

Do you plan on these pellets going in any direction besides west? If not, you can have the New() proc do this already:

    Pellet
icon='Bullets.dmi'
icon_state="Pellet"
New()
..() //and here
walk(src,WEST)
spawn(5) del(src)
In response to Speedro
Thanks, but my intention was to have Pellet's dir set from Boom_Bullet. That way, I could create copies of Pellet that all went in different directions, rather than hard code multiple copies of Pellet that whose only differences were the direction they walked. :x
In response to Gravity Sandwich
So like this:

obj
var
countdown=10
Boom_Bullet
icon='Bullets.dmi'
icon_state="Boomer"
New()
..() //here
while(countdown)
countdown--
step(src,SOUTH)
sleep(0.5)
new/obj/Pellet(src,WEST) //pass src and the direction you want it to go to the\
New() proc of the Pellet

del(src)
Pellet
icon='Bullets.dmi'
icon_state="Pellet"
New(obj/o,direction)
..() //and here
loc = o.loc //so the location of the pellet is the same as what we passed back,\
src/Boom Bullet

walk(src,direction) //and the direction is whatever you want when you create the\
new bullet.

spawn(5) del src
In response to Gravity Sandwich
The issue is that New() runs in full before your code has a chance to assign the direction. Instead of forcing the pellet to move in New(), do it in a separate proc that you call after assigning any variables you need to.
In response to Speedro
Aha, it's working perfectly. Thanks a million for all the help~