ID:139185
 
Code:
locs+="Mountain peak:[xh],[xy],1"

and
usr<<"[locs]"


Problem description:
I know this is small problem, but I am going to run into it again in the future. When I output the locs list, it gets clustered up. I wanted to ask how to make every list variable have separate lines when list is sent?
for(var/x in locs)
usr<<"[x]"


=P
In response to Last Strike Entertainment (#1)
Nope, it doesn't work.
In response to Martys1103 (#2)
...Lol? Provide a snippet of how you're using it.

EDIT: Make sure locs is a -list- var/list/locs
In response to Last Strike Entertainment (#3)
Last Strike Entertainment wrote:
EDIT: Make sure locs is a -list- var/list/locs

And make sure that you've initialized the list, otherwise it's just a string and you're concatenating text to it.
In response to DarkCampainger (#4)
I will add more code so you could understand it better. I thought it would be simple to answer at first (like a simple text macro to force new line), but it seems it's more complex than I thought.

var/list/locs
var/P=0

mob
Generate_world()
var/highs = input("How many high points?") as num
var/H
for(H=highs, H>=1, H--)
var/xh=rand(1,world.maxx)
var/xy=rand(1,world.maxy)
new/turf/high(locate(xh,xy,1),rand(10,20))
locs+="Mountain peak:[xh],[xy],1"
P++
world<<"[P]\th mountain peak made at [xh],[xy],1"
world<<"All mountains are made."

verb
locs()
usr<<"[locs]"


In response to Martys1103 (#5)
Wait, so do you actually want a list? Or do you just want a text string with line-breaks in it?

If the former, you need to initialize your list:
var/list/locs = list()


And then to output its contents:
for(var/A in locs)
world<<A


However, if you just need one long text string with line breaks, you can use the \n escape character to insert a newline:
var/locs = ""

locs+="Mountain peak:[xh],[xy],1\n"
In response to DarkCampainger (#6)
Thank you, it worked. I wanted the first one. I didn't think you can use list() that way, right now I'm searching DM guide to see if I missed something about list() in there. Also, is list() always needed if you make a list without any initial contents?
In response to Martys1103 (#7)
Martys1103 wrote:
Thank you, it worked. I wanted the first one. I didn't think you can use list() that way, right now I'm searching DM guide to see if I missed something about list() in there. Also, is list() always needed if you make a list without any initial contents?

Typecasting a variable as a list doesn't actually create a list, it still holds null until you give it a value. A list is actually an object; just like mobs, objs, images, datums, and so on. It needs to be initialized. This can be done with new, list(), or with square brackets [len]. The reference explains all three methods.

I personally prefer list(), but I know a lot of people use the other two methods.