• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

[GM Studio 1.4] How to store tuples?

607

Member
Hi, it's me again!

I am trying to store coordinates into a list. However, there is no supported tuple data type in GML. It also doesn't seem possible to declare my own class. I tried using an array, but it gets changed by later actions, even after adding it to the list.
For example:

Code:
example = ds_list_create();

for (xcor = 0; xcor < 5; xcor++)
    for (ycor = 0; ycor < 4; ycor++)
        {
            var coords;
            coords[1] = ycor; coords[0] = xcor;
            ds_list_add(example,coords);
        }
Will result in the list example only containing arrays consisting of a 4 and a 3; that is, if the coords array isn't reused later on in the code.
How can I store separate coordinates in each entry on the list?
With objects, it is no problem to reuse the same names, but apparently within an instance (or within an event, maybe), it is. How do I fix this, or get around it?
 

chamaeleon

Member
Hi, it's me again!

I am trying to store coordinates into a list. However, there is no supported tuple data type in GML. It also doesn't seem possible to declare my own class. I tried using an array, but it gets changed by later actions, even after adding it to the list.
For example:

Code:
example = ds_list_create();

for (xcor = 0; xcor < 5; xcor++)
    for (ycor = 0; ycor < 4; ycor++)
        {
            var coords;
            coords[1] = ycor; coords[0] = xcor;
            ds_list_add(example,coords);
        }
Will result in the list example only containing arrays consisting of a 4 and a 3; that is, if the coords array isn't reused later on in the code.
How can I store separate coordinates in each entry on the list?
With objects, it is no problem to reuse the same names, but apparently within an instance (or within an event, maybe), it is. How do I fix this, or get around it?
Try var coords = array_create(2, 0); to initialize a new array every loop, so GMS does not attempt to reuse the same one over and over.
 
  • Like
Reactions: 607

607

Member
Try var coords = array_create(2, 0); to initialize a new array every loop, so GMS does not attempt to reuse the same one over and over.
That's it! (except the , 0 shouldn't be there) I feel a bit dumb now, for assuming that array_create didn't exist, just because it is not required to use it in most circumstances. >.< Thank you, I was not expecting such a simple solution!
 
Top