ID:144392
 
Code:
obj
mirror
icon = 'mirror.dmi'
dir=SOUTH
Enter(obj/O)
if(isobj(O)&&istype(O, /obj/projectile/beam))
walk(O,src.dir)
return ..()


Problem description:

When the beam enters the mirrors location, it simply keeps on moving the direction it was going. Can somone tell me what's wrong?

I have taken into consideration that src actually may be O, and if that's the case, how to I define the mirror?
The last case scenerio I can think of is that return ..() isn't the proper way and it has something to do with .=..()
any help would be nice, thanks.
erm, hello?
In response to Avren
I don't think anybody wishes to answer you.

*watches as countless people answer correctly*
Avren wrote:
Code:
> obj
> mirror
> icon = 'mirror.dmi'
> dir=SOUTH
> Enter(obj/O)
> if(isobj(O)&&istype(O, /obj/projectile/beam))
> walk(O,src.dir)
> return ..()
>

Problem description:

When the beam enters the mirrors location, it simply keeps on moving the direction it was going. Can somone tell me what's wrong?

First of all, you don't need to check BOTH if O is of type /obj, then check if its of type /obj/projectile/beam. Only do the latter.


I have taken into consideration that src actually may be O, and if that's the case, how to I define the mirror?

No. It is correct. src is the mirror. If src was deleted (therefore null), the proc would have stopped.

The last case scenerio I can think of is that return ..() isn't the proper way and it has something to do with .=..()
any help would be nice, thanks.

Talking [expletive deleted] about my advice behind my back? :P
No, that isn't the problem

The problem is, that the mirror is an /obj. While all atoms may have the Enter(), etc procedures, they are called when an object enters the same tile on the map ONLY for turfs, its their special behaviour. It makes sense, because the atom is attempting to enter inside the turf. However, as you probably have understood already, Enter() is called for mobs and objs when an object tries to enter INSIDE the mob/obj (like, into his "inventory").
What you need to do, is change the mirror to a /turf so it has the functionality you need. (dont stop reading. Also, if whats below seems complex, dont shy away from it, it isnt)
However, you may want to keep it an /obj, so it has /obj's functionalities, like being able to move. In that case, add the "turf/Enter() functionality" to /objs. This is by creating a new procedure for atom/movables, and whenever an object has entered a turf, you call the the new procedure for each obj and atom in the turf, with the object that entered 'src' as an argument, to let the object know who 'stepped on it'. For more info, read:
http://bwicki.byond.com/ByondBwicki.dmb?TriggeredObjs
In response to Kaioken
Yeah, that makes sence; the reason I need it an object is because people lay them around and lazers will bounce off them.
In response to Kaioken
That whole trigger thing isn't working for me...
obj
mirror
icon = 'mirror.dmi'
dir=SOUTH
Trigger(obj/O)
if(isobj(O))
walk(O,src.dir)

proc
Trigger(obj/O)
O.Trigger() //I think this is part of it; I don't have any idea what i'm supposed to put here!
turf
Entered(O)
for(var/obj/Obj in src.contents)
Obj.Trigger(O)
..()
In response to Animay3
Well... I don't really know what you're trying to do... but if it's something like Leftley's game... try the bump proc... because you don't want it to really be IN the object... and make the objects density 1...
In response to Avren
What we are doing is defining a new proc. It's kinda movement-system related. Like the movement system (ultimately, atom/movable/Move()) calls atom/Enter() when a movable enters the atom, we want a new proc to be called when a movable "steps on' (enters the same turf as) the atom/movable (you (and the Bwicki) replace the latter with /objs only, but it's probably a good idea to make it for movables so if you actually want mobs to do something when stepped on, you can ("hey! get off me!" message :d)).

If you look up procs like Entered(), you'll see their default action is nothing. So should be your new proc's default action. This is because these procedures are meant and designed to be overriden with special actions.
Here's the code more like it should be;
atom/movable/proc/Trigger(atom/movable/S) return null //by default, do nothing!
obj
> mirror
> icon = 'mirror.dmi'
> //dir=SOUTH //*1
> Trigger(obj/projectile/P) //override default behaviour.
> if(istype(P)) //*2
> walk(P,turn(P.dir,180)) //*3
> return ..() //return the return value of the parent proc. currently this is useless, but in the future you might have changed behaviour on the parent proc
> turf
> Entered(O) //when an object (movable) enters a turf...
> for(var/atom/movable/mov in src.contents)
> mov.Trigger(O) //call the proc for all movables in the turf, with the object that "stepped on" them as an arg
> return ..() //return value of the default/parent proc


*1: A. dir is SOUTH by default. :P
B. just dynamically set the dir as you see fit when object is created via code, or via the Map Editor instance editor (see here [link])

*2: You probably want only projectiles to be deflected. It would'nt make sense if, for example, you throw a rock at a mirror and it turns around coming back. :P (You might not have any other objs that currently move, but there's a fair chance you will in the future (I hinted at an item Throw() verb >.>), so might as well make it more robust.
istype()'s 2nd arg is omitted. This is a shortcut; it's like you put the type the var was typecasted as in the 2nd arg (so that line is the same as istype(P,/obj/projectile)). It's described in the reference entry for it.

*3: Do you want the object to always go back in the direction of the mirror? Possibly not. Objects can hit a mirror and not be facing it! For example, mirror.dir may be SOUTH, but a projectile can hit it from EAST.
This approach uses the handy turn() proc (look it up) to flip the projectile's direction around (turn by 180) and send it flying back in that direction.