I'm not sure if that's the correct term for it, but I can't find it in the F1 doc, so I'll just ask here :) Is there anyway to type a var? Like:
RzLib_Races.Name
RzLib_Races.HP
etc...
(RzLib_Races being a list)
ID:179336
Jan 18 2002, 3:15 pm
|
|
In response to Lesbian Assassin
|
|
Another way to do this (that might be closer to what you're looking for, but ultimately lacks the on-the-fly flexibility of the associative list) is the datum object. Thank you so much! |
In response to Dreq
|
|
No problem... and read my response to your verb hiding request on General. I think you're looking in the wrong direction there entirely. You don't need to hide your verbs, just clarify their sources.
|
In response to Lesbian Assassin
|
|
Ok I know how to add items to the list now:
BlaList.Add(list(HP=35,MHP=53)) etc. But how would I go about listing just HP? How about pulling data from just HP? |
In response to Dreq
|
|
usr << "You have [BlaList[HP]] Health Points."
That should work. If it doesn't, blame the excessive pizza and mixed sodas... |
In response to Foomer
|
|
eheh, nice try, but no poptato!
|
In response to Dreq
|
|
Okay, then I'm not going to think about it tonight!
|
In response to Foomer
|
|
Instead of having like
Races.Name[3] Races.Icon[2] I'll have Races_Name and Races_Icon.... |
In response to Dreq
|
|
Dreq wrote:
eheh, nice try, but no poptato! To access the associative value of something in an associative list, refer to it through the list(Not sure how to explain that, but heres an example!) mob/player/var/level = 0 var/list/Players[0] // initiate a new list world/New() ..() Players = new() // create the list mob/player/Login() ..() Players += list(src=src.level) // add src to Players, and store src.level as the associative value mob/verb/Who() for(var/mob/player/a in Players) src << "[a] [Players[a]]" Granted, in this case its much easier to just refer to [a.level] but thats not the point :) |
In response to Dreq
|
|
Dreq wrote:
eheh, nice try, but no poptato! 'Round here, we only say cotato. -AbyssDragon |
In response to Dreq
|
|
Dreq wrote:
Ok I know how to add items to the list now: This isn't quite correct. You need quotes around "HP" and "MHP": BlaList["HP"]=35 To retrieve the data, do the same: stat("HP",BlaList["HP"]) I'm a big fan of associative lists, but I don't think it's really the best choice for most stats, since these tend to be simple vars for simple purposes. Lummox JR |
In response to Dreq
|
|
The problem with your method is that (I think) you're adding a list to the list.
BlaList = list("HP"=20,"MP"=35) sets BlaList equal to a newly created, two item list, with each value associated with a number. Doing BlaList.Add(list("HP"=20,"MP"=35) may (I'm not sure) be adding 1 item to the list that is BlaList... this item is itself a list. If you need to add an item to an associative list after the list itself has been initialized, do it this way: BlaList["HP"] = 20 BlaList["MP"] = 35 If you want to do everything at once, do it at the beginning: BlaList = list("HP"=20,"MP"=35) |
In response to Lummox JR
|
|
Lummox JR wrote:
I'm a big fan of associative lists, but I don't think it's really the best choice for most stats, since these tend to be simple vars for simple purposes. From what I've seen, excessive use of lists to store things like stats tends to be MUD damage. It's indicated by statements like:
var/current_health = stats[3] + stats[5]
In MUD-land, they are actually being clever by not hard-coding stats, but most of the techniques don't apply to DM and just make things more complicated. Also even in MUD-land they would make it vastly more readable if they used defines for the numbers, to make it read like so:
var/current_health = stats[HEALTH] + stats[HEALTH_BONUS]
If you want to use the "attributes in a list" approach in DM, obviously you'd use associated lists. However, in DM the need for using non-hardcoded lists isn't really there. As it happens, mob and object variables are stored in savefiles based on name, and if a mob or object was stored before a new variable was added it's no problem. When the variable isn't found in the savefile, the default value for it is simply used for the mob/obj. So unless you have a well-defined need to do otherwise, just make your stats variables. Life will be easier all-around. |
var/list/thingamajiggy = list ("width" = 10, "weight" = 20, "size" = "bloody big")
Rather than defining the whole list at the start though, you can just create the empty list and access it this way:
thingamajiggy["width"] = 6
You read from it in the same fashion:
if (thingamajiggy["width"] > 9) usr << "That's one wide thingamajiggy you've got there."
Another way to do this (that might be closer to what you're looking for, but ultimately lacks the on-the-fly flexibility of the associative list) is the datum object.
Define thingamajiggy at the root level:
thingamajiggy
var
width
height
size
thingamajiggies are not objs, mobs, turfs, or atoms... they do not have names and have no default representation on the game map... they don't even have a location yet. But you can do this:
mob/var/thingamajiggy/thingamabob
and then, if the usr has a thingamjiggy set to the thingamabob variable, you can access usr.thingamabob.height, .width, and .size