ID:160457
 
How would I code for when you enter a certain spot,
*like stepping on a button*
which I know that would use the Entered() proc,

at
locate(src.x,src.y+1,src.z)

it will place
/obj/switchopen

and when they step off the spot *Exited() proc*, it will remove the object that was placed at
locate(src.x,src.y+1,src.z)

I'm not sure how I would code that.
turf/button
icon = 'button.dmi'
Entered(mob/M)
var/obj/switchopen/SO = new()
SO.loc = locate(M.x,M.y+1,M.z)
Exited(mob/M)
for(var/obj/switchopen/SO in view(src))
del SO


Hope that's what you were trying to do. :D
In response to Andre-g1
Andre-g1 wrote:
> turf/button
> icon = 'button.dmi'
> Entered(mob/M)
> var/obj/switchopen/SO = new()
> SO.loc = locate(M.x,M.y+1,M.z)
> Exited(mob/M)
> for(var/obj/switchopen/SO in view(src))
> del SO
>

Hope that's what you were trying to do. :D

well the Entered() part is what i need, but the Exited() is a lil off, becasue in a game which there are multiple people,
instead of the "in view(src)" it would have to be a remove it at the "locate(M.x,M.y+1,M.z)"

otherwise, using the above code u stated, becasue if someone else in the game triggers the button that is right next to the other button, when they exit it would remove the switch that appeared for you also. since they will be in the same view as you.

only way the above would work, is if the /obj/switchopen/ was only visible to the person who triggered the button, which that would work, but I wouldn't know how to do that.
In response to ElderKain
Ah, I didn't know that.

Then hmm ;

turf/button
icon = 'button.dmi'
Entered(mob/M)
M.switchh = new()
M.switchh.loc = locate(M.x,M.y+1,M.z)
Exited(mob/M)
if(M.switchh) del M.switchh

mob/var/obj/switchh


I think that'd work. *shrug*
In response to ElderKain
You could make it look for objs (or one obj) in that turf above it easily enough as well, ironically the latter with another usage of the locate() proc (look up locate() and mind the 'in Container' syntax).
var/obj/myobj/O = locate() in locate(x,y+1,z)

Confused much? >_>" You could also switch that last locate(coordinates) for get_step() to make it slightly more convenient, as only one step away is needed (otherwise, you couldn't really use it).

Or, to make it basically as robust as possible, you could assign the turf a reference to the obj it created, so it is 100% sure which obj was created by it and not by something else.
turf/button
var/obj/switchopen/myswitch //declare a var to store the object
Entered() //you don't even actually need the argument just for this
if(!src.myswitch) //if myswitch is null (false), which means it hasn't created and assigned an object yet (the default value of the variable is null)
src.myswitch = new(get_step(src,NORTH)) //set the var to a reference to a new instance of /obj/switchopen at our wanted location
Exited()
if(src.myswitch)
del src.myswitch //simple and elegant. =P


Actually another thing you should do for complete robustness is make sure the location turf you're using actually exists, since if the turf is accidentally at the top y-coordinate on the map or something, it will break as there won't be another turf above it.

EDIT: Ah, Andre beat me to it, kinda. =P
In response to Andre-g1
Andre-g1 wrote:
Ah, I didn't know that.

Then hmm ;

> turf/button
> icon = 'button.dmi'
> Entered(mob/M)
> M.switchh = new()
> M.switchh.loc = locate(M.x,M.y+1,M.z)
> Exited(mob/M)
> if(M.switchh) del M.switchh
>
> mob/var/obj/switchh
>
>

I think that'd work. *shrug*

hmmm, but how does that place the /obj/switchopen icon because, I don't know how it woul call the object that is supposed to appear.
In response to ElderKain
It will create an obj of type /obj, because Andre defined that var as that type. My similar code creates it as /obj/switchopen.

The following:
var/obj/switchopen/O = new /obj/switchopen(Location)

is equivalent to
var/obj/switchopen/O = new (Location)


It's just a shortcut (look up new() for more detail).
In response to Kaioken
Kaioken wrote:
It will create an obj of type /obj, because Andre defined that var as that type. My similar code creates it as /obj/switchopen.

The following:
var/obj/switchopen/O = new /obj/switchopen(Location)

is equivalent to
var/obj/switchopen/O = new (Location)

It's just a shortcut (look up new() for more detail).

i have this now
obj/switchopen
icon='turf1.dmi';icon_state="open";name="";density=0

mob/var/obj/switchopen = new()

turf/area/switch
name=""
switchtrigger
icon='turf1.dmi';icon_state="switch";name="";density=0
Entered(mob/M)
M.switchopen = new()
M.switchopen = locate(M.x,M.y+1,M.z)
Exited(mob/M)
if(M.switchopen) del M.switchopen
but all it does is when I enter the spot nothing appears, and when exit the switch area the turf area where the object was suppose to appear, the turf gets erased.
In response to ElderKain
You've got 2 things wrong there. First, you defined your mob variable as of type /obj, not /obj/switchopen. It's just a var named "switchopen" but its defined type is /obj. Read here to see how to properly define a var.

Second, the obj you're creating has no location, so of course it doesn't show up. Due to you falling to change its location properly, it will also be deleted due to garbage collection.
            M.switchopen = new()
M.switchopen = locate(M.x,M.y+1,M.z)


As you can see you are setting the same variable twice... first it's set to a reference to the obj which is right, bu then you change the switchopen variable to a turf at specific coordinates, overwriting the value of the obj. You're not changing anything's actual location. You should also just use new()'s argument to put the object at a location instead of doing it manually (with the loc var). You can use the code I posted previously as reference.