ID:2568130
 
Code:
Owner
verb
New_Create_Verb()
set category = "Owner"
switch(alert("What Do You Want To Do Create?","","Object","Turf"))
if("Object")
var/T = input("Type In The Objects ID") as text|null
if(!T)
return
else
for(var/obj/O as null|anything in typesof(/obj))
if(O.ID == "[T]")
var/obj/OB = new O(usr.loc)
view()<< "<font color=green>[usr]:Creates A [OB.ID]"
return

if("Turf")
return


hi, its been awhile since being on here and im trying to get to know coding again, I am trying to make my Create verb more better by giving lets say objects and ID, then using the create verb to type the object ID to create it. I get an error when I use the verb and does not create anything, anyone have any ideas where im going wrong in the code. thanks:

You're trying to check the value of a variable on an object that doesn't exist. Your loop is looping over type-paths, not actual objects.

There's a trick in DM using initial() that lets you do this without creating a new object first though.

for(var/object_type in typesof(/obj))
world << initial(object_type:ID)


Keep in mind, this trick can't be used on const-type vars.
In response to Nadrew
ok, so how would I go about coding it into what I already have, sorry for asking but been years since I coded on here, trying to refresh my brain
The purpose of these forums isn't to be hand-fed the result (unless it's something simple).

What I posted should be more than enough for you to look at and figure out how it applies to what you're doing. If you're not quite up to that yet, you'll probably want to work on a few smaller learning projects while reading through the guide and the various tutorials posted on the forum.

Not to be mean or anything, but this boils down to a fairly basic understanding of the language so just giving you the answer would probably be more harm than good because you'd be skipping over properly learning one of the basics you really need to have to really leverage any language to your needs.
In response to Nadrew
that's not a problem, but is this the only way to get a var from an un made obj? like is there anyway to like pull an icon from an obj code and make it link to the obf path to create?
The trick I showed is an internal shortcut that pulls initial variables from the table that stores them for usage later.

To access the actual variables of something, it has to be initialized (created), since a variable doesn't point at an object until that object exists.

With the code I posted you'd get the initial icon of an object type, as it was set in the code.

The usage of initial() isn't actually pulling the value from an object at all, it's just using the internal mechanic that lets initial() work, in that the initial value of all variables remains known to the engine at all times so it can be easily used via initial(). The reason the trick works at all falls on how the compiler handles the semi-colon operator.
code
Owner
verb
New_Create_Verb()
set category = "Owner"
switch(alert("What Do You Want To Do Create?","","Object","Turf"))
if("Object")
var/list/items = list("Road Block"=/obj/SingleFence)
var/T = input("Type In The Objects ID") as text
if(!T)
return
else
for(var/O in items)
if(O == "[T]")
var/obj/OB = items[T]
new OB(usr.loc)
view()<< "<font color=green>[usr]:Creates A [T]"
return

if("Turf")
return


I figured a way to do the create by text but It needs me to create a list of all the main objects I create but I don't mind doing that, it works just how I wanted it to
If you're using an associative list with id = type, you shouldn't loop through it to find the match. This is enough:
var id = input(...)
var type = items[id]
if(type)
new type(usr.loc)
// etc.

Of course, it only works if the ID is an exact match. If you want to get approximate matches (e.g. case insensitive), then you'd have to search the list.