ID:167115
 
How do i create a list and how do i add or substract something from it?
var/list/My_List = list()

My_List += BLAH

My_List -= BLAH

My_List.Add("hi")

My_List.Remove("hi")


I suggest reading the dm guide and reference
In response to A.T.H.K
I also suggest using Add() and Remove() ALL the time.

-Doh
In response to XxDohxX
I suggest you don't. Operators beat procedures, and I suggest using Add() or Remove() when you're dealing with more than one object.
In response to Crashed
Crashed wrote:
I suggest you don't. Operators beat procedures, and I suggest using Add() or Remove() when you're dealing with more than one object.

Crashed is correct Add is only good for more then one object other wise just use the operators
In response to A.T.H.K
Is there some reason for that? I use Add and Remove for everything, but I might not if there was actually a good reason not to. += and -= look like garbage when they're used in large blocks of code, whereas Add and Remove add valuable readability. I really appriciate the "readable coad" approach when I can get at it.
In response to PirateHead
Same here. I'd love to know why we should use operators and not the procedure. Surely there must be some reason behind that.
In response to CaptFalcon33035
Thanks.

Is it possible to display the list in a stat or anywhere else?
In response to A.T.H.K
Strange,
I tried out the code A.T.K.H. posted but my compiler says "bad argument definition" for the last statement.

I tried out the example in DM reference and it says the same thing for the last line.
In response to Starter
Works perfect for me show me how your using it and make sure the list exists..
In response to A.T.H.K
A.T.H.K wrote:
Works perfect for me show me how your using it and make sure the list exists..

well i simply copied the code you provided to test how it works.

My_List.Remove("hi") //This line is bringing up the 'bad argument definition'

If I remove this line then,

My_List.Add("hi") //This line is bringing up the 'bad argument definition'

If I remove this line also,

My_List += BLAH //This line is bringing up 4-5 errors.

Same with the other line. If I remove that line then the first word of my program(ie. World) is giving errors.

Am I supposed to write something before the,
var/list/My_List = list() //??
In response to Starter
My_List += BLAH - Theres nothing for BLAH

He was just giving you an example, You'd have to define it.
In response to Starter
Yes it is possible, but not by just showing the actual list. You have to loop through the list, then show that.

Example:

for(var/anything in My_List) //Loop through the contents of the list
world << "[anything]" //Output the contents



-XxDohxX
In response to Starter
Starter wrote:
well i simply copied the code you provided to test how it works.

Don't copy code if you tested by coding it yourself you might have learnt something extra
In response to XxDohxX
Well, in the statpanel, placing a list as the argument of stat() shows every item in the list.

stat(listname)
In response to CaptFalcon33035
I defined an obj and mob and yet it says bad argument definition.

when i use '+=' it says 'instruction not allowed here'

when i use '.Add' it says 'bad argument definition' or 'undefined proc'

BUT when i use 'var/list/SimLi = list(new/mob/Charmander)' and try to display this, then it is working. So I guess I cannot add anything.

Can anyone send a demo file to [email protected]?
In response to Starter
var/list/Things = list()
var/mob/M = new/mob/Charmander
var/mob/Q = new/mob/Charmander
Things += M
Things -= M
Things += Q
Things -= Q

Things.Add(M)
Things.Add(M,Q)
Things.Remove(M)
Things.Remove(M,Q)


etc etc etc its not hard at all
In response to A.T.H.K
same problem still

But its not saying 'bad argument definition' anymore. Its saying .Add() or .Remove() is 'undefined proc' and += or -= are 'duplicate definition'

In response to Starter
You defined it as var/whateverlist=list() . Not var/list/whateverlist=list()
In response to Starter
Starter wrote:
same problem still

But its not saying 'bad argument definition' anymore. Its saying .Add() or .Remove() is 'undefined proc' and += or -= are 'duplicate definition'

var/list/MyList[]

mob/Login()
MyList+="BYOND Staff: "
MyList.Add("Dan","Tom","Lummox Jr","Shadowdarke","Nadrew") //the ones I heard of.

src<<"BEFORE THE WORLD WAR"

for(var/X in MyList)src<<X //display the items in the list to you

src<<"AFTER THE WORLD WAR"

src<<"[MyList[1]][src.key]" //Direct accessing of items in the list
src<<"Due to recent events, BYOND has gone bankrupt. This world will now be shutdown."
world.Del()
Page: 1 2