ID:141277
 
Code:
var/list/list1=list("whatever"="whatever","Yea"="Yea")//and so on
mob/var/list/list2=list()
mob
proc
procname(A)
if(src.variable)
src.list2+=list1[A]


Problem description:
obviously this wont work, but what im trying to do is get one entry from list1 added to list2, i could do it in an extremely tedious way, but i need it done simply. I cant for the life of me get this to work D:
Rushnut wrote:
obviously this wont work

Really? FYI it could work with a proper argument supplied. ;P
(Though you've confuzzled one of the var declarations a bit when writing the post; list2 is a global var)

but what im trying to do is get one entry from list1 added to list2

I fail to see the problem here. Surely you know how to access that 'one entry from list1'? (if not, off to reading on lists in the DM Guide and Ref you go!) If so, then this is extremely straightforward. Access that entry... and then... add it to list2. I [probably ;D] couldn't make it more complex if I wanted.
In response to Kaioken
If i knew how to do that then i wouldnt be here would I? -.-'
In response to Rushnut
For some reason, you are more concerned with making a "clever" remark than actually paying attention or responding to the other things I've said which could have gotten you closer to solving your problem. Oh well.

Rushnut wrote:
If i knew how to do that then i wouldnt be here would I? -.-'

I might as well reply to that. Eh, ideally, you wouldn't be here even if you didn't know how to do that, because you'd have figured out that if you don't know how to do basic management of lists, then you should learn how to work with lists. If I may borrow the smiley, -.-' it seems like a natural reaction one would take, rather than go the forums (which you should go to after learning, if you've encountered a problem). As you might imagine, it would be pretty tedious if we had to teach every single BYOND developer how to use X/lists and the forum would be quite a cluttered mess.
---
That said, you still haven't clarified what is particularly problematic here. It looks like you know this basic stuff:
List += thing //add thing to list

world << List[1] //output first item in List
world << List["aa"] //output the associated value of the item "aa" in the list

From here all you need to do is combine the 2 principles, which is still very basic. e.g.:
var/first = List[1]
List_2 += first
//or...
List_2 += List[1]
In response to Kaioken
Which is my problem,
List2+=List1[A]

Seems to add ALL the entrys from List1 to List2.


Edit, this is the specific bit of code


mob/player/client/proc
Unlock_Icon(A)
switch(A)
if(1)
if(src.Unlockchar1<=0)
src.Unlockchar1=1
src.BonusChars+=bonus_character_list[A]
(...)
In response to Rushnut
Found the problem, it was in the way i was using the lists afterwards, thanks anyway :O
In response to Rushnut
src.BonusChars+=bonus_character_list[A]

Since that line will only be reached if A equals 1, this is indeed proper to attempt to add the first element of bonus_character_list to BonusChars. However, this naturally requires that both vars are correctly set to initialized lists in order to work. The apparent problem here is that BonusChars isn't set to a list; it's set to its default value of null, and so when you try to add something to it with += you're effectively just setting it's value. i.e.,
var/X = null + "AAA"
//equals:
var/X = "AAA"

In your case, you seem to have....
src.BonusChars = null + bonus_character_list[A]


EDIT: Ahh, a little late. Was this actually the problem or not, then?
In response to Kaioken
nono, the list was
mob/player/client/var/list/BonusChars=list()

So the list was set up correctly, the problem was... sigh, here goes my reputation


bonus_character_list was the list full of entrys, well when actually using these (the select character list) instead of checking the list of unlocked characters in BonusChars, I set it to check the list of all the bonus characters in bonus_characters_list...

*crys*
In response to Rushnut
Eh, well that happens to everybody. :P At least it's an outcome that makes sense out of this Code Problems topic that didn't seem to actually have a [posted] problem, hehe.
In response to Kaioken
HardeHardeHardeHa... *steals back emoticon* -.-' Ban puns are bad!
In response to Rushnut
Rushnut wrote:
nono, the list was
mob/player/client/var/list/BonusChars=list()

So the list was set up correctly, the problem was... sigh, here goes my reputation

I think the type path to your 'client' mob gives a worse reputation than a simple mistake, because this indicates a serious, serious design error ;)

Segmenting your game logic such that any mob could be with or without a client is going to save you a *lot* of pain, if you have any mobs that aren't controlled by a player. Which you presumably do. And /player/client ? As opposed to /player/noclient ?
In response to Alathon
My game features non human players :p