ID:273713
 
Hey everyone. In my game text strings are items. This means the player's inventory is done like this:

mob
var
Slot1 = ""
Slot1Amount = 0
//etc etc etc


This does however pose one major problem. How do I get it to hold values like power and speed or the many other variables usually held in an obj's variables.

I was thinking of adding everything to just one text string I can pick to pieces later like "Sword 2 3 5 6 7 8" but I don't know how to specify the individual parts of that text string. The other method is that I use many variables. How would you go about this problem?
It would be MUCH easier if you have the actual object set in the variable and access its information that way. For example:
mob
var
obj/tech // Note that the following variables are defined to have the variables/procedures of /obj/tech
slot1
slot2 // etc. You can use a list() in its place as well if you wanted.


obj/tech/Sword
verb/Equip()
set src in usr
usr.slot1 = src
usr << "You have equipped [src.name]"


mob/verb/Check_Slot1()
if(!src.slot1)
src << "You have nothing equipped!"
else
src << "Slot 1: [src.slot1.name] - atk:[src.slot1.atk] def:[src.slot1.def]"


This way, if you need to make critical changes, you do not have to erase everyone's save files.
Why, why, why would you EVER need to store the objects as a text string?

mob/var
obj/Slot1
Slot1Amount = 0
// Etc


// Assigning an item

obj/items/sword/o = new
Slot1 = o

// outputting

src<<"[Slot1.name] - [Slot1.power]"
In response to Emasym
You have both missed the point sorry. I like my items as text strings. That's just the style I will use.

Can anyone please tell me how I can do it using text strings? Thank you.
In response to Kyle_ZX
While everyone will keep on telling you that's nonsense, here goes.

Assuming the text string is the name of the object.

1) Adding all objects to the game world (dump them somewhere in a corner), or creating them

var/path = text2path("/obj/items/[Slot1]")
var/obj/o = locate(path) in world
//or
var/obj/o = new path
if(o) world<<o
//after doing all the sutff you wanted
del(o)


Problem of course being seperate categories in your obj tree.

To circumvent that, you'd have to use a really, really bad system which will loop through all the items and create a new one, as it's not possible to check the name of an item without creating it
(If you've got an item, say, Bastard Sword, the path closest to representing that will be Bastard_Sword)

var/obj/o
for(var/i in typesof(/obj/items) - /obj/items)
o=new i
if(o.name==Slot1) {world<<"Found [o]";break}
else del(o)


I certainly don't have to point out how ridiculous that is.
So, yeah, your style of saving them as text strings is just.. Bad.
In response to Emasym
The system I want to use doesn't even involve the letters obj. You again have the missed the point entirely. Perhaps a screen shot will help.

http://img130.imageshack.us/img130/317/51849434.png

I am asking how to use text strings ONLY to make items. Get that into your heads please.
In response to Kyle_ZX
While datums are much better, params are what you are looking for.

You can use params2list to convert them to an associated list and access each part that way.
"name=Sword&power=15&weight=10"
In response to Kyle_ZX
Get this into your head: System is downright sloppy.

Easy way: Params as Pirion suggested

Somewhat easy way: Creating a new object with your string, getting the data from it, and adding the variables

mob/verb/Name()
var/list/l = getStatsFromPath("Sword 2 3 5")
var/obj/sword/o = new
o.name=l[1]
o.atk=l[2]
o.def=l[3]
o.spd=l[4]
world<<"[o] with [o.name], [o.atk], [o.def], [o.spd]"


proc/getStatsFromPath(name)
var/list/l=new
while(findtext(name," "))
l+=isnum(copytext(name,1,findtext(name," "))) ? text2num(copytext(name,1,findtext(name," "))) : copytext(name,1,findtext(name," "))
name=copytext(name,findtext(name," ")+1)
l+=isnum(name) ? text2num(name) : name
return l
In response to Pirion
Thank you Pirion for actually just answering my question.
In response to Kyle_ZX
Now imagine you want to delete an item.