ID:1800719
 
Problem description:Using a piece of code from forum_accounts library again and I'm playing around with it. I think to myself I don't want to have to program each trap separately so is their anyway for me to put them into a list? Example below.

Code:
turf
spikes
icon_state = "spikes"
New()
..()

var/obj/o = new /obj()
o.icon_state = "spikes-overlay"
o.layer = MOB_LAYER + 1
overlays += o

stepped_on(mob/m)
var/turf/t = locate(x,y+1,z)
if(istype(t,/turf/spikes)) //so instead of a lot of istype() I want to try checking from a list instead. I tried using the in operator but couldn't get that to work, so I'm doing it wrong or it can only be done with objects?
m.take_damage()




turf
spikes
density = 1
Spike1
icon_state = "spikes"
New()
..()

var/obj/o = new /obj()
o.icon_state = "spikes-overlay"
o.layer = MOB_LAYER + 1
overlays += o
Spike2
icon_state = "spikes"
New()
..()

var/obj/o = new /obj()
o.icon_state = "spikes-overlay"
o.layer = MOB_LAYER + 1
overlays += o
mob
Bump(A)
if(istype(A,/turf/))
var/turf/T = A
if(istype(T,/turf/spikes))
world<<"lal"


You can just make spikes group and place others in that group than locate it via bump.
I just face palmed so hard about the datums. Thanks guys.
Oh nevermind my respond. You want it so you can walk on trap not bump into it. Bump() require density = 1
No problem Phat T it was still helpful either way.

Also I just realized instead of a New() for every trap I could just do this.

Edit: I also just realize that's what pirate just pointed out to me. Inheritance -.-

turf
traps
New()
..()

var/obj/o = new /obj()
o.icon_state = "[name]-overlay"
o.layer = MOB_LAYER + 1
overlays += o

spike1
icon_state = "spikes"
name = "spikes"

spike2
icon_state = "spikes-2"
name = "spikes2"
I have done now Kaiochao. I also just read that using turfs in lists is quite bad apparently.

    stepped_on(mob/m)
var/turf/t = locate(x,y+1,z)

if(istype(t, /turf/traps/))
m.take_damage()
There's nothing wrong with having turfs in a list, or having a turf var that's a list. There are some things to keep in mind though:

- If you have a turf var that's a list, do not initialize it until it's needed. (The same applies to objs and mobs with list vars--never instantiate the list till you need it.)

- If a list contains turfs, make sure that list doesn't get saved along with an obj or mob. Likewise for any var/turf belonging to anything that might possibly be saved. Such vars should be declared as tmp, for safety. The reason is that if a turf gets saved anywhere, its contents will save with it--and that could include a mob such as another player.
Okay thank you for the information Lummox. I think I need to go read your associative lists tutorial.