ojars
|
|
Posted on: June 10, 2019, 05:22:01 am |
|
|
Joined: May 2019
Posts: 16
|
Hi! I wrote a simple test program. In a o_game create event var arr[3];// = array_create(3); arr[2] = 52; arr[1] = 4; arr[0] = 16 list = ds_list_create(); ds_list_add(list, arr); then in a o_game draw eventdraw_set_color(c_black); draw_set_font(font_0);
var arr = ds_list_find_value(list, 0);// expected to get an array draw_text(200, 200, "list size = " + string(ds_list_size(list))); draw_text(200, 220, "array length = " + string(array_length_1d(arr))); for (var n = 0; n < array_length_1d(arr); n++) draw_text(100, 100 + n * 20, string(arr[n])); The only thing I got was: list size = 1 array length = 0 Perhaps I'm doing something wrong? Is there a way to get access to arrays stored in ds_list?
|
|
« Last Edit: June 10, 2019, 05:29:45 am by ojars »
|
Logged
|
|
|
|
Goombert
|
|
Reply #1 Posted on: June 10, 2019, 07:03:42 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
We don't have that list function yet, but i can actually add that for you, that's doable now! I'll see if I can get to it tonight.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
hpg678
|
|
Reply #2 Posted on: June 10, 2019, 07:35:12 am |
|
|
Location: Barbados Joined: Mar 2017
Posts: 283
|
Greetings and salutations!
i mentioned your problem to one of the developers, so he's going to fixed the problem very soon. Apparently it has do with one of the functions. So please be patient until then.
|
|
« Last Edit: June 10, 2019, 07:55:11 am by hpg678 »
|
Logged
|
[compromised account]
|
|
|
|
hpg678
|
|
Reply #4 Posted on: June 10, 2019, 08:07:38 am |
|
|
Location: Barbados Joined: Mar 2017
Posts: 283
|
ok here's a little update to your problem relayed to me by Goombert....one of the major developers - Don't declare the array with 'var'
- use array_create(<size>) function to allocate memory for the ds_list......it'll be much faster
arr = array_create(3); arr[2] = 52; arr[1] = 4; arr[0] = 16 list = ds_list_create();
and in your draw_event for (var i = 0; i < array_length_1d(arr); ++i) { ds_list_add(list, arr[i]); }
for (var i = 0; i < ds_list_size(list); ++i) { show_message(string(ds_list_find_value(list, i))); }
this should work now.
|
|
|
Logged
|
[compromised account]
|
|
|
|
Goombert
|
|
Reply #6 Posted on: June 10, 2019, 08:51:41 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Everything hugar said is correct. The following part of the code I gave him can actually go wherever you want it, in the create too. It is copying the array to the list, element by element. for (var i = 0; i < array_length_1d(arr); ++i) { ds_list_add(list, arr[i]); }
So the difference between ENIGMA/GM var arrays and data structure lists is subtle but important. In ENIGMA the var arrays are actually Lua tables of variants. The data structure lists are C++ std::vector of variant. Variant is the light weight type which is single dimensional in the case of reals. It uses NaN Boxing to store floating point and scalar values. Var array functions: https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Universal_System/var_array.cppData struct list functions: https://github.com/enigma-dev/enigma-dev/blob/eabb1b474d5abf7e2d58ae3eccf4ba875208a9c9/ENIGMAsystem/SHELL/Universal_System/Extensions/DataStructures/data_structures.cpp#L1203In general, you probably want to use lists exclusively over arrays since they can not only be passed around by id, but their operations are more efficient. They won't be much different from var arrays, they just don't have to do as much work and are written in C++. And ENIGMA again is actually implemented close to GM so you should expect similar results going in the direction of any of the above.
|
|
« Last Edit: June 10, 2019, 08:54:14 am by Goombert »
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
ojars
|
|
Reply #7 Posted on: June 10, 2019, 09:28:53 am |
|
|
Joined: May 2019
Posts: 16
|
Yes, I can use lists exclusively. I wonder why I didn't imagine that sooner... lists stored into list... Anyway thank you. EDITED. As I wrote in my post https://enigma-dev.org/forums/index.php?topic=2992.0, I just found a way how to implement structs. I even managed to store struct into list and access it. circle is a struct str = ds_list_create(); circle.x = 300; circle.y = 400; ds_list_add(str, circle); That code was in o_game create event, and this is in a Draw event: var data = ds_list_find_value(str, 0); draw_text(data.x, data.y, string(data.x)); and the result was seen on the screen, as expected - 300;
|
|
« Last Edit: June 10, 2019, 02:37:24 pm by ojars »
|
Logged
|
|
|
|
Goombert
|
|
Reply #8 Posted on: June 10, 2019, 02:48:39 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Hey, that's great! I will still look into fixing the old EGM format saving/loading from the lgmplugin for you. It just makes it easier to save that information.
PS: Also my recommendation about using lists is actually the same as Mark Overmars in the GM8 manual. It's true for scientific reasons that the data structures are faster when you consider operating on lots of data.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
ojars
|
|
Reply #9 Posted on: June 10, 2019, 03:10:41 pm |
|
|
Joined: May 2019
Posts: 16
|
I do believe, that data structures are fast. I wonder why it's not possible to use struct member functions. As I wrote in my previous post, when I tried to use member function, I got an error Event[8, 0] Check `o_game::draw...Syntax error in object `o_game', Draw event:0: Line 24, position 30 (absolute 770): Unknown function or script `get_area' I consider to use structs as lightweight objects that don't move.
|
|
|
Logged
|
|
|
|
Goombert
|
|
Reply #10 Posted on: June 10, 2019, 05:39:03 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
That's just the syntax checker being greedy about what's a script. Needs a fix and then a CI test to keep it working.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
|
Goombert
|
|
Reply #12 Posted on: June 15, 2019, 01:05:39 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
That's correct, yeah, what's it doing in ENIGMA? I understood you, you want to store the reference/pointer to the var array inside the ds list.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
|
|
|