ID:2101105
 
(See the best response by Ter13.)
mob/Bump(mob/src)
..()
if(istype(src,/turf))
return//return...
if(istype(src,/mob))
return//return..
var/S
S = new/obj/huecomundogarganta
if(!istype(S,/obj/huecomundogarganta))
return//return..
if(istype(S,/obj/))
if(usr.client)
usr.loc = locate(rand(50,150),rand(50,150),7)
spawn(100)
del(S)
else return

Basically what's happening is I'm trying to create an object that can be entered, I've basically made it but I'm running into problems where I get teleported by objects that aren't supposed to teleport me. Can anyone help me fix this issue so I can only be teleported by the huecomundogarganta Object?

Uh, don't name your argument src. That's asking for a world of hurt. Name it anything else, like M.

usr is also not valid here; this is a proc, not a verb.
It doesn't work if i don't use usr, I've tried using src and it does nothing. The proc is a bump proc and it works, I just need to figure out the part where it has me bump into any obj and transports me, instead of just bumping into the specific obj i want to transport me. I get what u mean though, and I changed it accordingly. Except that broke it, so I changed it back.
mob/Bump(atom/M) // dont use src and use atom/M
..()

if(istype(M,/turf))
var/turf/c = M
if(c.density)
return
if(istype(M,/mob))
var/mob/c = M
if(c.density)
return

.. atc


What Lummox JR is trying to say is don`t use


mob/Bump(mob/src) // rather use mob/a , mob/b, mob/c ... or whatever you want src is not valid.
I would rather do atom/M to and than defind them like in my example.
But this isn't helping solve the problem, lol. It has absolutely nothing to do with the problem, and I don't see the point in fixing something that isn't broken. What I'm using is working, I just need help fixing the problem I wrote down in the original post, but it seems like nobody is looking past the first half of the first sentence.
Best response
I don't see the point in fixing something that isn't broken.

Do you know who Lummox is? He's the guy who maintains the language and software.

If he's saying your code is broken, odds are that it's broken.

What I'm using is working

No. It isn't. The entire thing is broken. Every bit of this code is wrong in some way.

but it seems like nobody is looking past the first half of the first sentence.

Agreed. But it doesn't really matter because this entire thing is wrong:

mob/Bump(mob/src) //NEVER name an argument src.
..()
if(istype(src,/turf)) //...Why?
return//return...
if(istype(src,/mob)) //WTF are you even doing?
return//return..
var/S
S = new/obj/huecomundogarganta //Never do this in a movement-related function.
if(!istype(S,/obj/huecomundogarganta)) //why would this EVER be true?
return//return..
if(istype(S,/obj/)) //why are you checking the type of an object you already created? why not use else?
if(usr.client) //usr is invalid in procs
usr.loc = locate(rand(50,150),rand(50,150),7) //usr is invalid in procs
spawn(100) //this is wrong. spawn is a block level instruction
del(S) //manual deletion? why?
else return //why is this logic branch even here?


This entire snippet makes zero sense. At all. You are teleporting when bumping into random objects because you are creating a type of /obj/huecomundogarganta every time you bump into any object on the map, then checking if it is an /obj, which is ALWAYS true, and then randomizing the location of the player.

How to fix it:

Here. This is what you were probably trying to do:

atom
proc
Bumped(atom/movable/o) //create a reciprocal to Bump() so that we don't have to istype() everywhere
movable
Bump(atom/o)
o.Bumped(src) //call the reciprocal function
..() //call the default action


Now that we have our code hook ready for use:

obj/huecomundogarganta
Bumped(mob/m)
if(ismob(m)&&m.client)
m.loc = locate(rand(50,150),rand(50,150),7)


Do you see how much simpler that is?

The problem before was that you were embedding the teleporting behavior in the wrong object's structure. It makes more sense to create a reciprocal function and then define the teleporting code under the reciprocal for the object that is being bumped into than it does to make the huecomundogarganta object's behavior be a part of the /mob's structure.


@Lummox:

The built-in movement functions actively encourage completely backward code like this (no offense Bob21). Because there are no reciprocal functions people assume that they HAVE to do it all in /mob/Bump() rather than /atom/Bumped() being a thing.

Basically, Bumped(), onEntered(), onExited(), onEnter(), onExit(), onCross(), onUncross(), onUncrossed(), onCrossed(), etc. should have been built into the language from day one because they encourage users to write code that just plain doesn't suck. Not having them encourages users to misunderstand polymorphism completely and it's why the majority of the pass-around knowledge around here just sucks and hasn't improved in almost two decades.
In response to Ter13
Ter13 wrote:
The built-in movement functions actively encourage completely backward code like this (no offense Bob21). Because there are no reciprocal functions people assume that they HAVE to do it all in /mob/Bump() rather than /atom/Bumped() being a thing.

Basically, Bumped(), onEntered(), onExited(), onEnter(), onExit(), onCross(), onUncross(), onUncrossed(), onCrossed(), etc. should have been built into the language from day one because they encourage users to write code that just plain doesn't suck. Not having them encourages users to misunderstand polymorphism completely and it's why the majority of the pass-around knowledge around here just sucks and hasn't improved in almost two decades.

Fair enough. I agree the design should probably have been reciprocal from the outset.

I do wonder if it's a feasible thing to add Bumped() now, now that so many games have it. Probably.
In response to Bob21
Bob21 wrote:
But this isn't helping solve the problem, lol. It has absolutely nothing to do with the problem, and I don't see the point in fixing something that isn't broken. What I'm using is working, I just need help fixing the problem I wrote down in the original post, but it seems like nobody is looking past the first half of the first sentence.

Here's my perspective on such things: When code has several problems that jump out at you, there isn't any sense in fixing the logic errors until the code is made cleared of the more obvious issues. It's like performing surgery in a dirty environment; the long-term outcome is probably not going to be good. Having usr in a proc, and a local var named src, are things that are liable to cause complications in any fix.
But see, what u guys have suggested, isn't working, lol. I need it to add onto the code I have, not change it entirely and make it not work. I think I need to explain to u guys what the code does, lol. It states that whenever a player bumps into a turf or other mob, nothing will happen, but when they bump into the huecomundogarganta object, they're teleported away. The problem is, they also get teleported by any other object, which is what I'm trying to fix. Btw I'm fairly sure its not a proc, because proc isn't written anywhere on here.
In response to Bob21
ter literally explained everything for you and gave you the code
Zag, I tried what he suggested, it did not work. I think I need to explain what I need help with exactly. I'm trying to have it detect objects that I bump into and make it so the only one that teleports me is the huecomundogarganta object. I'm NOT trying to change the rest of it and make it not work.
if u wanna ignore everything ter said:
obj/huecomundogarganta
Crossed(mob/m)
if(ismob(m)&&m.client)
m.loc = locate(rand(50,150),rand(50,150),7)

Thanks Zag :D lol I see what u did with Ter's code, and it worked, which basically solved the thread. He used bumped instead of crossed, and gave a definition for bumped, and it didn't work, but I think because u used crossed instead, it worked.
He used bumped instead of crossed, and gave a definition for bumped, and it didn't work, but I think because u used crossed instead, it worked.

Gee, I wonder why I used Bumped():

Bob21 wrote:
I'm trying to have it detect objects that I bump into and make it so the only one that teleports me is the huecomundogarganta object.

but when they bump into the huecomundogarganta object

mob/Bump(mob/src)

Such a mystery.


Bump() is called when a movement fails due to a dense object.

Crossed() is called when a movement succeeds and the mover overlaps an object for the first time.