show ds_list element like array [u528]
Reporter: fervi | Status: closed | Last Modified: May 01, 2018, 04:05:24 pmHello
using
[ | 1]
We display the first element ( I do not know why zero is not numbered ) list.
However, Enigma does not support this ...
Example Script: (Works on GM: Studio)
http://gmclan.org/up6184_12_dslist.html
name_ds_list[| 1]
https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/accessors.html
@fervi Don't mean to be rude, I can see why it's useful, but the way GMS does it just doesn't make any sense and it was only done that way because of how screwed up GML is. The plain [] subscript operator will be much better once ENIGMA is capable of doing it. GMS 2.0 for example also likely won't have that nonsense, assuming of course that it isn't vaporware.
ds_list blah [1];
?
@JoshDreamland Maybe we should reopen this as a feature request for the subscript operator on data structures? I mean... I would kind of like such functionality myself in the future just without the stupid extra symbols.
my_ds_list[1]
, nor my_ds_list.at(1)
, because the runtime of list::at
is O(n)
. Consider this code:
for (int i = 0; i < my_ds_list.size(); ++i) {
sum += my_ds_list.at(i);
}
If there are a couple hundred elements, you're probably fine. If there are 1,000 elements, your game could start to lag. If there are one million elements, your game will cease to be a game; it will be spending twenty minutes computing the sum each time.
The point of a list is for quick concatenation. If you want array access, use a vector. If you want a vector in GM, just use an array.
var my_array;
my_array[1] = 10;
Access on an array in ENIGMA is O(1)
. So the above code will not take 20 minutes with one million elements, but instead may only just begin to cause any visible lag. It would take less time for the code to run using an array with one million elements than for that exact same code to run over one thousand elements using a list.
I understand wanting a more concise syntax for maps, and one has been planned for a long time (though no one is seriously working on it, right now). But choose your data structures carefully.