Legacy GM (SOLVED) Export DS_list as one string

Hello GMC!

I have a DS_list question.

I've created a DS_list and now I'm trying to export it as text. More specifically to the clipboard.

I've tried this:

code = ds_list_write(global.custom);
clipboard_set_text(string(code));

However, the text that are copied to the clipboard are around 9600 characters, whist the DS_list contains around 300 values.

So, my question is:

How do I export the values from a DS_list as ONE continues string that I can later copy to the clipboard?


Thank you all! Keep safe.
 

DaveInDev

Member
in the manual , about ds_list_write , it's clearly specified :
The returned string is not a human readable string, but rather a dump of the contents of the data-structure

So I would say that it really depends on the content of your list. But you can browse through the list.
For example, if it's a list of numbers, you could write :
GML:
var s = "";

for(var i=0; i<ds_list_size(global.custom); i++)
    s += string(global.custom[|i]) + ",";

clipboard_set_text(s);
 

Bobious

Member
If I'm not mistaken, the ds_*_write functions basically dump the contents of he DS's into a non-human-readable string, that can be used to save it to a file, and then load it later. To get something readable you would need to use a while loop to go through the list and add it to a string, because I'm pretty sure there is no function to do that kind of thing.
 
in the manual , about ds_list_write , it's clearly specified :
The returned string is not a human readable string, but rather a dump of the contents of the data-structure

So I would say that it really depends on the content of your list. But you can browse through the list.
For example, if it's a list of numbers, you could write :
GML:
var s = "";

for(var i=0; i<ds_list_size(global.custom); i++)
    s += string(global.custom[|i]) + ",";

clipboard_set_text(s);
That worked great! Thank you so much.

Follow up question. What would be the best way to do the reversed? Getting the clipboard string back into a DS_list?

Is that possible?
 
P

ParodyKnaveBob

Guest
Howdy, Mr. Vincent,

Sooooo, looking at the manual, json_encode() is intended for DS usage like what you seek. You should be able to test and figure out how to reverse the process from there.

Regards,
 
Howdy, Mr. Vincent,

Sooooo, looking at the manual, json_encode() is intended for DS usage like what you seek. You should be able to test and figure out how to reverse the process from there.

Regards,
Yes, that seems to be a option. Gonna look more into it.

Meanwhile, I think I can also achieve splitting up the string and inserting it back into a DS_list.

If you have any ideas, please let me know :)

I'm gonna keep poking at this.
 
Last edited:
I actually managed to get it to work everyone!

This is how I retreived it back into the game.

GML:
var str = argument[0] //string to split
var delimiter = argument[1] // delimiter
var letDelimiter = false // append delimiter to each part
if(argument_count == 3)
    letDelimiter = argument[2]
var global.stagecode = ds_list_create()
var d_at = string_pos(delimiter, str)
while(d_at > 0) {
    var part = string_delete(str, d_at , string_length(str))
    if(letDelimiter)
        part = part + delimiter
    str = string_delete(str, 1, d_at)
    d_at = string_pos(delimiter, str)
    ds_list_add(global.stagecode, part)
    if(d_at == 0 && str != "")//last string without delimiter, need to add too
        ds_list_add(global.stagecode, str)
}
 
Top