ID:1255002
 
Keywords: grab, grabbing, mob, verb
(See the best response by Albro1.)
Code:
mob/var
grabbed=0
grabee=null

mob/verb/grab(mob/M in get_step(src,dir
set category = "Skills"
grabee=M
M.grabbed=1
mob/Move()
if(!grabbed)
for(var/mob/M in oview())
if(grabee==M)
M.loc=locate(x,y,z)
..()
mob
verb
release()
set category = "Skills"
grabbed=0
grabee=null


Problem description:
I understand that this is my second post out of 3 hours, but I tried and tried, but I cant seem to do it. What I need is so that the player can also grab obj's, not just mobs. When I try to code it, I get a bunch of errors.

Can someone help? (Hoping this is the only big error I get in a while)
Stop using mob for everything and start using obj. Create variables for obj, reference obj, etc.
In response to Albro1
I want to be able to grab both mobs AND obj's. Not just obj's
So go up a level. What is the parent of /mob and /obj?
In response to Albro1
For mobs its "M"

obj's so far does not have a parent.
Best response
In response to TheScatman95
Objects and mobs are both under atom/movable. Have you read the guide? :)
I read it, and I already understood all of that. But that doesnt help me figure out how to set up a grabbing obj and mob ALL on the same verb. IF I wanted too, I can easily ode to it grab objs and mobs on sparate verbs, but that is tendeious to me, and other players.

So can you help me? :L
atom/movable/verb/grab()
In response to TheScatman95
The answer to your problem is understanding inheritance to it's full potential and applications.

Let's take Boubi's example.

If you give atom/movable a verb called Grab

that means all mobs and objects in your game would then have a grab verb.

What I would do, however is leave that verb blank as it, it does nothing.

Then in the places and instances you want it to actually do something you write it out, like so.

atom/movable
verb
Grab()


mob
Grab()//this already exists, just filling in what it does.
usr.loc=src.loc
src.loc=usr.loc//swaps locations.


obj//objects will follow a user when grabbed
var
tmp/grabbed=0
Grab()
if(~grabbed)//if it hasn't been grabbed yet by someone
grabbed=1
//code to make the object follow the user
//then turn off being grabbed.


In both cases this does something different, even though it's the same verb.

Let's say you have monsters and players in your game.

mob/player
Grab()
//does one thing

mob/monster
Grab()
//does another


obj/item
Grab()
//does yet another thing


obj/Statue
Grab()
//does finally something different



In each instance, everytime you create a mob/player from now on, there is no need to re-write the verb. It's like that with each type of movable atom, or basically, there's no need to set up a verb on a player by player basis-- and if you are doing it that way, you should re-think the way it's being done. Programming will help you simplify or automate a lot of things -- once you grasp the understanding of it. In this case, you are saying you get it, but if you fully understood it, you wouldn't have a problem. I'd take their advice if I were you and study more.

In response to Dariuc
Dariuc wrote:
    Grab()
if(~grabbed)//if it hasn't been grabbed yet by someone
grabbed=1
//code to make the object follow the user
//then turn off being grabbed.



I'm not sure if the ~ was a typo on your part, as ~ and ! are right next to eachother; but it's probably bad convention to use a binary operator on something intended a boolean, sure it works, but it looks bad.
In response to Super Saiyan X
If you prefer:
 !grabbed