i have that ds_map on the screan shot and that code to:
function scr_player_res_data_send(_username, _buffer) {
var _list_id = ds_map_find_value(obj_server._players_eq_stats, _username);
// Sprawdzamy, czy _list_id to faktyczna lista
if (ds_exists(_list_id, ds_type_list)) {
var _player_res_json = json_stringify(_list_id);
buffer_write(_buffer, buffer_string, _player_res_json);
show_message(_player_res_json);
} else {
show_debug_message("Błąd: Brak listy dla gracza " + string(_username));
}
}
but only thing that i got from this code is 74 that is id of "aaa". How can i get full ds_list that is on this key "aaa"?
#help with getting ds_map_find_value
1 messages · Page 1 of 1 (latest)
By "only thing that i got from this code" you mean what you got from
show_message(_player_res_json); ?
Lists (and other ds_ stuff I believe) hold a pointer to a resource, so you would have to loop through it
var list_contents = "";
for (var i = 0; i < ds_list_size(_list_id); i++) {
list_contents += string(_list_id[| i]) + ", ";
}
show_message(list_contents);
Additionally, you can't json_stringify data structures, you need json_encode for that
Any reason you're not using structs and arrays?
I have to save it to a json file (so I don't lose it after a reset) for that I use ds_map because it's easier to convert and save to .json. If I used regular arrays I wouldn't have any problem except that I would have to assign numbers to users to refer to specific data by.
that message i got when run your script (i have 74 list in this ds_map and all i got is just their id-s
i make this _player_eq_stats decoded and got _player_res_decoded
I have to save it to a json file (so I don't lose it after a reset) for that I use ds_map because it's easier to convert and save to .json.
How is it easier?
If I used regular arrays I wouldn't have any problem except that I would have to assign numbers to users to refer to specific data by.
I'm not proposing to use arrays in place of map
Structs instead of maps, arrays instead of lists
Both are easier to use, have more functions, are automatically garbage collected
Ahh, yeah, haha, you have lists inside lists 😄
well, you would have to loop through inner lists too
Or just use arrays - show_message would show you all it's contents without any trouble
do you know any good tutorials for this, i can try if you tell that is better
you mean to change it to this?
https://manual.gamemaker.io/monthly/pl/#t=GameMaker_Language%2FGML_Overview%2FStructs.htm&rhsearch=Structs&rhhlterm=Structs
I read this article and wonder why I haven't used it before (:
Yes, and they are quite similar to maps
Data structures (ds_something) are rarely used nowdays, usually only when you're forced by some built-in function using them.
Structs and arrays are the way
Haven't watched it, but seen SamSpade recommended a bunch
so may look at these if manual won't be enough
https://www.youtube.com/playlist?list=PLwgH1hDD0q1FLsKwe8jZ_08YZa5yuMe6E
but only question i have now, how to convert this and save as a file?
This should be mostly up to date I think
https://www.youtube.com/watch?v=R84mR52QaMg
This is also very good read:
https://web.archive.org/web/20240712094453/https://tabularelf.com/basic-saving-and-loading/
thx a lot
my last question about this:?
if i make something like this
_res_data =
{
aaa : [
[0,0,0,0],
[1,1,1,1],
[2,2,2,2]]
}
it will normal work with 2d arrays?
Aye, this is correct
2d array inside a struct
i see that my .json with this data is already format to this (:
next question (:
how can i make that this key _username will change depend of what i set it?
because now when i set "aaa" it make me "_username"
_shop_res_data[$ _username] = ..., can be used to both set and get
$ for $truct
ds_maps have something similar, ds_map[? _username]
but this is to find something, i need to make new struct with this
i know that i do something wrong but don't know how to make it right
i read that GameMaker does not allow you to dynamically add new keys to regular JSON structures
Not sure what that suppose to mean, but you definitely can add new key/value pairs to structs
how?
Here, if you're trying to do roughly the same as in picture above (have an array named _username inside _ship_res_data struct) you just gotta drop the curly braces encasing your array
_ship_res_data[$ _username] = [
[0, ...
i read how can i add value of key from struct but i can't find how to add key to existing struct
when i do this its just add me "aaa": null ,"_username" : ...
and when i do egzacly like you its says that is not set before reading
Would have to see what exactly you're doing
Also the full error message
and its need to be some _ship_res_data[$ _username] = [
data: [0, ...
struct[$ newkey] = some_value;
It's the same as using struct_set
With this function you can set the value of a given variable in a struct. You supply the struct reference as well as the name of the variable to set the value of as a string (see example code below), and then finally the value to set (can be any valid data type). If the variable does not exist already in the struct it will be created and then assigned the value.
Arguments
struct: The struct reference to set
name: The name of the variable to set (as a string)
val: The value to set the variable to
_ship_res_data does not exist
Where do you define it?