var/list
Bomb_Atom = list()
Bomb_Hydrogen = list()
obj/bombs
Atom
//...
Hydrogen
//...
New()
..()
var/a = pick("A","B","C")
name = "Grade [a] [name]"
proc/Sort()
if(istype(src, /obj/bombs/))
var/a = "[src.type]"
var/b = copytext(a, 12)
var/c = text2path("Bomb_[b]")
c += src
Problem description:I want to move the object into the appropriate list. I used copytext to grab the name I need but can't find a way to use "var/b" to get the object into the list.
Jester619 wrote:
The right words here are more like "put" or "add", not "move". Don't confuse lists with the movement system (or the special contents list) - when you add, say, an object to a list, you're not moving it. Similarly, you can add the same objects into multiple lists, so treating list-adding as moving is misleading. The only time movement would happen is when the special contents list is modified, but that only applies to that one unique list.
If you weren't looking at it like that anyway, sorry, I'm just making sure. =P It's a common misconception.
Well, you just can't do it like that, the way you've tried. Let me show you what your code actually executes like:
First, basically you can't modify anything with only a type path. You need an actual object whom to change. Second, you've went about it entirely wrong here; as said, no such type paths as "Bomb_Atom" will ever exist:
So, you need another way, one that actually makes sense to the computer. I'd scrap what you currently have and do it quite differently, using the Power of Objects (/OOP).
First, about your current code: your istype(src,/obj/bombs) check is very redundant. Since that proc is one defined on the /obj/bombs type, the code in it will only ever execute on objects of that type - validating that is just a waste of time. In fact, if you're doing things properly, you should pretty much never have to check src's type at all, so keep that in mind.
Anyway, one method to do this could be this:
You could also do it dynamically for all the bomb types that will ever be in your game with a different sort of method (using a global associative list to keep track of the list of every bomb type). This may or may not be preferred, depending on your game:
The bombs list would then look like this at runtime, if you had 1 Hydrogen bomb and one Atom one initialized:
Legend: X_instance = a reference to an object instance of that type
Lastly - don't forget to remove the bombs from whatever list(s) they're in when they're deleted (by overriding Del())! This isn't what you'd call 'strictly necessary', but it's a very good idea.