ID:146297
 
Code:
    Bump()
for(var/obj/shooting/rocket)
if(rocket)
del(rocket)
del(src)
usr.money+=300
if(usr)
del(src)
usr.money-=600
else
return


Problem description: i need help with my bump, this is my first time using one and im not 100% how to use it, please dont tell me to look at tutorials or DM Guide cause i do, i just dont understant if very well

Ok, I'm confused, can you explain what your code does?
Bump() works like this. The mob/obj you've defined Bump() for will be src in the Bump() proc. So if you obj/Knife/Bump() and need to refer to the Knife, you say src. Now in the case of obj/Knife/Bump(), Bump() will only be called when the knife collides with something with density. The thing that the knife collides with can be defined by doing:

obj
Knife
Bump(atom/movable/A) //A is the thing collided by the Knife


Usually after Bump(), you should check if what we Bump()ed is a mob or an obj and then define A as a mob/obj.

obj
Knife
Bump(atom/movable/A) //A is the thing collided by the Knife
if(ismob(A))
var/mob/M = A //now M, which is a mob, is the thing the Knife collided with. To refer to the knife, use src. To refer to the thing collided, use M.
else if(isobj(A))
var/obj/O = A //now O, which is an obj, is the thing the Knife collided with. To refer to the knife, use src. To refer to the thing collided, use M.

In response to DeathAwaitsU
ok, so now my whole code is...

obj/Enemy
icon='air force.dmi'
icon_state="Enemy"
density=1
layer=MOB_LAYER
proc/Enemy()
while(src)
sleep(7)
step(src,EAST)
sleep(2)
step(src,EAST)
sleep(2)
step(src,EAST)
sleep(7)
step(src,WEST)
sleep(2)
step(src,WEST)
sleep(2)
step(src,WEST)
New()
.=..()
Enemy()
Bump(atom/movable/A)
if(ismob(A))
var/mob/M = A
if(isobj(A))
var/obj/O = A
for(var/obj/shooting/rocket)
if(rocket)
usr.money+=300
del(rocket)
del(src)
if(usr)
usr.money-=600
del(src)
else
return


but the problem is when i hit a plain with a rocket i get this runtime error

runtime error: Cannot read 0.money
proc name: Bump (/obj/Enemy/Bump)
usr: 0
src: Enemy (/obj/Enemy)
call stack:
Enemy (/obj/Enemy): Bump(Killer22 (/mob/PC))
Enemy (/obj/Enemy): Enemy()
Enemy (/obj/Enemy): New(Cloud (40,16,4) (/turf/airforce/cloud4))
In response to Killer22
How did usr come in to the picture?

You don't seem to understand indentation.

    Bump(atom/movable/A)
if(ismob(A))
var/mob/M = A
if(isobj(A))
var/obj/O = A
for(var/obj/shooting/rocket) //this is at a completely wrong place because this code will be run regardless of you putting if() statements above.
if(rocket)
usr.money+=300
del(rocket)
del(src)
if(usr)
usr.money-=600
del(src)
else
return
In response to DeathAwaitsU
i need the usr to lose money if he bumbs into the src
In response to DeathAwaitsU
ok, so, can you help me and tell me what is wrong, and why its not working?
In response to Killer22
You waited ten minutes to bump a post, good job.

~>Jiskuha
In response to Jiskuha
are you here to just say something, or you ganan help?
In response to Jiskuha
Jiskuha wrote:
You waited ten minutes to bump a post, good job.

~>Jiskuha

Hey! Didn't you say you would stop being so... mean?
Although, you should try to not bump your posts so early.
Please wait at least 24 hours.
In response to Killer22
If I was going to help, I would have. DeathAwaitsU has already helped you. Read his post.

~>Jiskuha
In response to Jiskuha
1    Bump(atom/movable/A)
2 for(var/obj/shooting/rocket)
3 if(ismob(A))
4 var/mob/M = A
5 if(isobj(A))
6 var/obj/O = A
7 if(rocket)
8 usr.money+=300
9 usr <<"Got one"
10 del(rocket)
11 del(src)
12 if(usr)
13 usr.money-=600
14 del(src)
15 else
16 return

yup, still not working, please point out where the problems
(Choose the number)
In response to Killer22
Did you even read my post explaining how Bump() works? You wouldn't have even thought of using usr if you had tried to understand it rather than trying to get your game to work.
In response to Killer22
I have already. You've put the coding in the wrong place.

Not to mention you seem to have no clue about how for() works.

What were you even trying to do by doing for(var/obj/shooting/rocket)?
In response to DeathAwaitsU
oh, now i know what your trying to tell me, your saying i cant use for(var/obj/shooting/rocket), your also telling me to put that in the if() rather than just have rocket, and your also telling me to put A in place of usr.

so, am i correct?
In response to Killer22
but if i have var/obj/shooting/rocket in an if, its asking if rocket is a variable, right?
In response to Killer22
I'm asking you what you think for(var/obj/shooting/rocket) will do (and therefore hinting that it's wrong to do it).

I'm telling you NEVER to use usr in procs (barring a few special ones like Click() ). And if we're not going to use usr, I've showed you how to refer to the thing collided and then refer to it as a more specifically (like whether it's a mob or an obj).

Basically, all you want is:

Bump. Is that thing a mob? If it is then refer to the atom collided as a mob. Next do what I need to in that if(). If it isn't a mob, check if it's an obj. If it is then refer to the atom collided as an obj. Next do what I need to in that if().
In response to DeathAwaitsU
oh, damn it, i was looking at the wrong post
In response to DeathAwaitsU
DeathAwaitsU wrote:
Did you even read my post explaining how Bump() works? You wouldn't have even thought of using usr if you had tried to understand it rather than trying to get your game to work.


no, you wrong, i did read it, i just did understand it till i read it again and noticed that the knife would be like the rocket, not the Enemy
In response to DeathAwaitsU
obj
shooting
rocket
icon='shooting.dmi'
Bump(atom/movable/A)
if(ismob(A))
var/mob/M = A
if(isobj(A))
var/obj/O = A
usr.money+=300
usr <<"Got one"
del(A)
else
return

now i have this and rather than giving me 300$'s and deleting A, its going right through it, do i have to call bump?
Page: 1 2