ID:142278
 
I'm not sure if BYOND just doesn't support this, or if I'm not editing the list properly. I'm trying to edit an associative list under a mob so I don't have to do it at runtime.

The below code will give two "left-hand side must be an object variable" errors.

mob/var/list/Stuff = list("stuff","things")

mob/Pie
Stuff["stuff"] = "cherries" //This line
Stuff["things"] = "crust" //and this line
//give errors
Sigh doesn't anyone use the Reference anymore god..

http://www.byond.com/docs/ref/info.html#/list/associations
In response to A.T.H.K
I assume you answered as if my question was "do associated lists exist in DM?". I'm sorry if I wasn't specific enoughg. What I ment by "does BYOND not support this" is does BYOND not support editing a value in an associated list with [] operator outside of a proc.
its
mob/Pie
Stuff = list("stuff" = "cherries","things" = "crust")
In response to Theosco
I know you can edit associative lists like that, for my actual code is mob/var/list/Evos = list("type","lv","water",etc etc). I just don't want to have to use the list proc for all my mobs, as that would result in a lot of extra typing and useless entries because some mobs don't have a water evolution. I guess I could just use list() because it doesn't matter if an entry is null or non-existant...
In response to Jeff8500
[link]

[link]

[link]

[link]

Hope those help its a amazing what the search feature does maybe you should try it?
In response to A.T.H.K
Thankyou, for once again failing to address the problem and giving a snarky remark. None of those are what I'm talking about! I know how associative lists work! I'm just asking if there is a way to edit one with the [] operator outside of a proc. Like I said, this code below would give errors:

mob/var/list/Associated_List = list("Stuff","Things")

mob
Associated_List["Stuff"] = "Things"


Nothing you have posted so far is related to the compiler error that would give (which I did supply) and why the [] operator doesn't work there.
In response to Jeff8500
I see what you're saying. As far as I know, there isn't a way to do that. I believe the reason why might be because it has to have some type of trigger to initiate it, other than simply placing it in the mob category or elsewhere. However, as I'm sure you know, an easy to make proc could be something like this:

mob/proc/List_Edit(var/variable,var/value)
Associated_List["[variable]"] = "[Value]"


Then to access it, all you'd have to do is List_Edit("Stuff","Things")
In response to Michael3131
Ah thankyou. Knowing that it was impossible to use the [] operator like how I wanted to use it is all I really wanted to know.
In response to Michael3131
That'd be a completely pointless proc, though, as you can probably work out.
Anyway, the reason you can't do it in an object definition, is because actual instructions can't run there - it's not in any proc, after all. You're basically fortunate DM is flexible enough to (virtually) allow some procs (new(), list()) and operators at compile-time, which basically ports them over to a New()-like position and those instructions run at runtime immediately when creating the object. However, instructions like List[x] = y cannot be understood by the compiler at compile-time, not to mention they require an object already being created to function correctly.
Of course, you can use New() yourself to initialize any object variables (and world/New() for global vars) that need to be set to complex expressions/procs that can't be done at compile time. A basic example:
mob/person
var/list/Stuff = list("x"=0,"y"=1,"gold"=1000)
poor
New()
src.Stuff["gold"] = 100


Note that the best functioning way would be to override the variable normally/completely at definition, but it can possibly not matter at all, for example if your code doesn't use initial() anywhere or some such (although it is used by default in object saving). You could probably make a #define or 2 to make the "full" syntax slightly more practical to use, if it's necessary:
#define usual_stuff "x"=0,"y"=1
mob/person
var/list/Stuff = list(usual_stuff,"gold"=1000)
poor/Stuff = list(usual_stuff,"gold"=100)
In response to Kaioken
Thanks, I might use the second method you described. Originally I just used New() for testing, but I wasn't sure if that could cause problems later on or not.