C++ Question : Equivalent expression in GML

Edgamer63

Member
Hello, i was wondering about : What would be the equivalent expression of:

Code:
std::unordered_set<glm::ivec3> vector

for (const auto pos : vector){
    
}
And this expression:

Code:
std::unordered_set<glm::ivec3> vector

for (const auto &pos : vector){
    
}
Well, just now i'm not working with shaders... so i really mean the equivalent of this expresion in GML (I mean, like lists and repeat statements)...

Thanks
 

GMWolf

aka fel666
Current GML (what I'm calling GML16) does not have sets or structs.

Rather than sets, you can use sorted lists, or maps. (Depending on the size lists can be faster than maps). (Btw, even in c++ avoid sets and unordered_set. Most of the time a vector with linear search will be faster)

We also don't have for each loops, just c style loops.

As for structs, a future version of GML (GML19 or GML20) will have "lightweight objects". But for now we have to make do with arrays and enums.

Assuming you use the lists variant, you would do:

Code:
enum vec3 {
_x, _y, _z
}


var vector = ds_list_create();

//Add a bunch of stuff to the list
ds_list_add(vector, [2, 5, 6]);
ds_list_add(vector, [8,5.5, 6]);


for(var i = 0; i < ds_list_size(vector); i++)
{
    var pos = vector[| i];
  
    pos[vec3._x] //equivalent to c++ pos._x;
}
With the uocoupco GML enhancement dealing with "structs" should become far easier but for now we have that clunky workaround.
 

Edgamer63

Member
So...


Code:
for(var i = 0; i < ds_list_size(vector); i++)
Is the Equivalent to? :

Code:
for (const auto pos : vector){
 
Top