ID:171862
 
Ok, I am having some trouble using the Bump function. I have written code so that it works when I have one type of mob(the player), but now I am making a game with monsters, and so I have other types of Mobs. The problem is I cant get the players attacks to hurt when they hit the mob. For example, one attack is a magic spell which is shot similar to a gun, and when the spell(moving ogject) hits a mob I want the hit mob to take damage. But when I try to access the hit mobs variables, such as hp it says undefiend variable. Here is how I am writing the Bump function. I am putting the function under each seperate object. I tried putting it under the individual mob, but I could not figure out how to tell the difference in objects hitting him. Heres the little bump code:

obj
magic
density = 1
icon = 'magic.dmi'
Bump(M)
world << "IM HIT!"//for testing
del(src)
M.hp--

M.hp is considered and undefiend var. But I have it defined under the mob. And isnt that how I access the variable, by using the "M." and then put the variable I want to access. If I could get some help on this that would be awesome. Or even a small tip would be great. Thnx to all for help, and sorry about the long post, I have a dendincy to just babble on.
Bump(mob/M)
if(ismob(M))

You never told it M was a mob.
In response to Airjoe
i changed my code so that it looks like that..and when i attempt to access the variables it still gives me the same error. I might have defined the multiple mobs incorrectly, but Bump works fine when I dont try and access a var. I am glad you tried to help, and I am sure I needed that..but it is still not working right. Very Strange...

Do you guys suggest I use procs for something like this...I have not used them much, but after looking at some example code, they seem very common.
In response to AdhesiveMAN
Airjoe, you still haven't declared M as a mob! You only checked to see if it was a mob, so you could do it a few ways, here are some:
Bump(mob/M)
Bump(M as mob)
Bump(M)
if(ismob(M))
var/mob/Mob=M
In response to JohnReaper
Look again, I definatly have Bump(mob/M) which is declaring it as a mob.
In response to Airjoe
Ahh, *slaps eyes*! Stupid things!
In response to JohnReaper
So should the code now look like this:

Bump(mob/M)
if(ismob(M))
var/mob/Mob=M
world << "IM HIT!"
del(src)
M.hp-- // Still not sure what this should reall be, M.hp? Mob.hp?


If this is what it should look like, then it still does not work. M.hp is still considered an undefined var. And if I make it Mob.hp then it says: 210:error:Mob.hp: compile failed (possible infinite cross-reference loop)
And I have no clue what that means. I GREATLY appreciate all the help i am getting. I have this feeling I messed another part of the code up..or did i do something wrong with the above code?
In response to AdhesiveMAN
Bump(mob/M)
if(ismob(M))
world << "IM HIT!"
M.hp--
del(src)

It should look like that, and perhaps the problem is that you don't have "hp" defined for mobs?
In response to JohnReaper
Well, although I love your help, del(src) deletes the little ball of magic, without that is say IM HIT a few times, which isnt good. And I am pretty sure I defined hp for the mobs. I have it like this:

mob
player // human player
var/hp = 100
test // test mob
var/hp = 100

And I have defined under world that player is the human mob:

world
mob=/mob/player

And when the humna player attacks, a small ball of magic comes out, it then Bumps into the test mob and should then take hp from the test. Thnx again for all those helping me.


In response to AdhesiveMAN
I dunno how good this is, but it seems to work for me:

Bump(mob/M)
for(M in world)
M.hp -= 10


By the way, you're defining hp as a different var for each mob. It'd be easier to do something like this:

mob
var/hp
player
hp = 100
test
hp = 80


That should make things easier.