ID:179602
 
Here's the problem. I need to be able to access a value based on an associated value. I'm not entirely sure how much sense I'm going to make, so bear with me please.

My player mobs have the following list

list/skills

This list contains skill names and associated level values

ex: skills["Melee Combat"] = 4

I'm trying to set up a verb that will add a skill to a player and deduct an appropriate number of points from the player. Here's where it gets fun. The cost varies depending on the 'setting'. For example, combat skills are more expensive in high action settings, and gun combat does not exist in medieval settings. Currently, I'm attempting to use a master list of skills with two elements:

list/skills_list[15][8] (15 skills, 8 settings)

Each skill (1-15) is set to a skill name ("Melee Attack" for example) and I want to put eight different values in the second element (the different point costs).
This is later reference when deciding whether a player has enough points to purchase the skill, and how many points to deduct (skill level * cost).

I tried it this way:

 skills_list += "Melee Attack"
  skills_list["Melee Attack"][1] =



It compiled alright, but I got wierd errors during character creation (where the lists are intialized):

 runtime error: cannot write to indexed value in this type of list
  proc name: CreateCharacter
  (/mob/creating_character/proc/CreateCharacter)
    source file: BESM.dm,375
    usr: the sapphiremagus (/mob/creating_character)
    src: the sapphiremagus (/mob/creating_character)
    call stack:
  the sapphiremagus (/mob/creating_character): CreateCharacter()
  the sapphiremagus (/mob/creating_character): Login()



I'd greatly appreciate any help on how to go about this =)

Thanks in advance
sapphiremagus wrote:
I tried it this way:
skills_list += "Melee Attack"
skills_list["Melee Attack"][1] = <cyber punk cost value>

Well, first off you shouldn't need the first line. What you probably want to do, though, is this:
skills_list["Melee Attack"]=list(attack value 1, attack value 2, ....)

Accessing the list may be tricky, so in most cases I'd try code like this:
var/list/skill=skills_list["Melee Attack"]
value=skill[1]

Lummox JR
I wish I could do somthing like this, too. It would help me a lot in making my text engine more expandable.
In response to Lummox JR
Hmm, that looks like it'd work pretty good. I only have one question =P

In a perfect world (ha!) I'd like to be able to use a skill name AND a setting name or number to reference a list and get a value back. Is that possible, or do I need to take the long way around?

I had this code in my add_skill verb:

</xmp>

var/s
s = input("What skill?","Skills") in list skills_list+"Never Mind"
if(s != "Never Mind")
var/l
l = input("What level of [s]?","[s]") as num
if(skills_list[s][setting]*l <= src.PCP)
src.skills+=s
src.skills[s] = l
src.PCP -= skills_list[s][setting]*l
</xmp>

Heh, I hope that illustrated what I was going for well enough =P. Anyway, is it possible to do something like that (not necessarily the same way, but using a similar mechanic)? I'm not sure, but I THINK I can do that with what you posted LummoxJR . .. . . . .*goes off to tinker*
while not just list the skill and its acc. value, and then make a univeral lookup table for all the skills? it would save a good deal of memory, and simplify things.

you could look at the skill name and find it in a second list, that list would point to a list of point values for advancement. it would reduce tons of redundancy, if you have lots of skills.
In response to sapphiremagus
sapphiremagus wrote:
Hmm, that looks like it'd work pretty good. I only have one question =P

In a perfect world (ha!) I'd like to be able to use a skill name AND a setting name or number to reference a list and get a value back. Is that possible, or do I need to take the long way around?

If you mean you want three varaibles to go into this, so that the list you read from by level is looked up by a skill name and setting, then try this:
var/exactskill="[skillname]:[setting]"
var/list/skill=skills_list[exactskill]
value=skill[level]

If you just want the skill name and setting in one and want to avoid the list-within-list thing, that's even easier:
var/exactskill="[skillname]:[setting]"
value=skills_list[exactskill]

This code works well only if you know the possible settings in advance. You may want to think up other code for more complicated situations.

I'm writing something on lists now that may help.

Lummox JR