ID:176929
 
Hey guys! I just started getting back into byond and one thing I never really got into was the Bump proc. Well, my bump looks like this:

mob
player
Bump(atom/Sign1)
alert("Welcome to my game.","Sign","Ok",)

Well, i wanted to know how to make it so this only shows up when i bump the sign. As of now it comes up anytime i hit anything on the same screen as the sign. :( Thanks in advance! Any help would be great!
SSTrunks7 wrote:
Hey guys! I just started getting back into byond and one thing I never really got into was the Bump proc. Well, my bump looks like this:

mob
player
Bump(atom/Sign1)
alert("Welcome to my game.","Sign","Ok",)

Well, i wanted to know how to make it so this only shows up when i bump the sign. As of now it comes up anytime i hit anything on the same screen as the sign. :( Thanks in advance! Any help would be great!

Try this

mob/player
Bump(obstacle)
if(obstacle.name=="Sign")
alert("I like cheese")
obj/sign
name="Sign"


But for a more robust bump, try this.


mob/player
Bump(obstacle)
if(obstacle.message!=null)
alert("[obstacle.message]")
obj/sign
var message="I like cheese"


-Project Zero
In response to Project Zero
Thanks a lot! Especially for the different codes, that was a realy help. Thanks again Zero! Later yo!
In response to SSTrunks7
Hehehehehe....ummmmmmm, sorry. I thought the code would work just by looking at it but unfortunetly, when I try to use the first code I get a Objects.dm:14:error:obstacle.name:undefined var
even tho I define it like Zero said to. I now have no idea what's wrong. Is there another mistake I made? Any help would be awesome! Thanks in advance!
In response to SSTrunks7
First, it should be atom/obstacle.
Second, the code is very, very bad. What if someone's name is "Sign?" The name var can be changed by players, and thus, nothing should be based on it. So use the type var.

mob/Bump(atom/Obstacle)
if(istype(Obstacle,/obj/Sign/))
var/obj/Sign/S = Obstacle
src << alert(src,S.message,S.name)

obj
Sign
var/message = "BLAH!"
name = "Not a sign"
In response to Garthor
Alright! I just got this working, thanks a lot Garthor!
SSTrunks7 wrote:
Hey guys! I just started getting back into byond and one thing I never really got into was the Bump proc. Well, my bump looks like this:

mob
player
Bump(atom/Sign1)
alert("Welcome to my game.","Sign","Ok",)

Well, i wanted to know how to make it so this only shows up when i bump the sign. As of now it comes up anytime i hit anything on the same screen as the sign. :( Thanks in advance! Any help would be great!

Well, there are two problems here.

First, there's no guarantee that you're hitting a sign; Bump() is called no matter what you hit, and Sign1 would be the name of the var representing what you bumped into. A better way to go about this would be something along these lines:
mob
player
Bump(atom/O)
O.Bumped(src)

atom
proc/Bumped(atom/movable/A)
// bumped by A
// do nothing by default

obj/sign
Bumped(atom/movable/A)
A << "<B>[desc]</B>"
You can then set your sign's desc var (all atoms have one) to what you want it to say.

The second problem you have is actually eliminated by the above code, because I didn't use alert(). (I find alert() to be fairly sloppy anyway. Reserve this for emergencies.) The problem is that alert() sends a box to usr by default, not to src. Unfortunately, Bump() will be called when you move and bump into something whether you initiated the movement or not. If something else tries to push you, for example, using Move(), then usr will not be your character and thus the alert box will go to the wrong player--or to a non-player, and cause an error. When you use alert() inside Bump(), send src as the first argument:
alert(src,"Hi","Sign")
You should do the same in any situation where src is correct instead of usr. Likewise if another var is meant to be the recipient of the box, use that instead. In my example above you could use alert(A,...) in the Bumped() proc.

Lummox JR
In response to SSTrunks7
Oops, alert should have src as the first argument, and it should alert src, not usr... changed accordingly.
In response to Lummox JR
Thanks a lot for the help. I just got it all to work fine with the upgrades you added. Thanks again!