• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Multiple Value Arrays

T

Thunder Lion

Guest
Hey guys I am trying to imagine how I would build a variable that allows me to store 2 or more values.
I am thinking of using arrays.
However this is what I am looking to do conceptually.

Variable: slot
Values: item, amount

slot[item,amount]

Is it possible for me to obtain these values within the brackets?

More rather can I read off the "string" say like this:
slot[cheese,10]
This means in slot I have cheese and I have 10 of them. How can I read these values to use them?
 

Lazzeking

Member
Hey guys I am trying to imagine how I would build a variable that allows me to store 2 or more values.
I am thinking of using arrays.
However this is what I am looking to do conceptually.

Variable: slot
Values: item, amount

slot[item,amount]

Is it possible for me to obtain these values within the brackets?

More rather can I read off the "string" say like this:
slot[cheese,10]
This means in slot I have cheese and I have 10 of them. How can I read these values to use them?
EDIT:
My bad, didnt read your request quite right.
 

Simon Gust

Member
2D arrays work.
you have your inventory as the array name and the first index is the slot and the second index is the type of info in that slot
Code:
inventory[0, 0] = "cheese";
inventory[0, 1] = 5;
And to make things more readable you can use enumerations to fill in the second index
Code:
enum inv 
{
  name = 0,
  amount = 1,
}
and do this instead
Code:
inventory[0, inv.name] = "cheese";
inventory[0, inv.amount] = 5;
the 0 being the current slot.
 
T

Thunder Lion

Guest
2D arrays work.
you have your inventory as the array name and the first index is the slot and the second index is the type of info in that slot
Code:
inventory[0, 0] = "cheese";
inventory[0, 1] = 5;
And to make things more readable you can use enumerations to fill in the second index
Code:
enum inv
{
  name = 0,
  amount = 1,
}
and do this instead
Code:
inventory[0, inv.name] = "cheese";
inventory[0, inv.amount] = 5;
the 0 being the current slot.
This was an idea I had. I suppose I should request this new feature in an update "reading off array coordinates".
 
C

CptChuckles

Guest
but when will we get tuples and true user-defined types? :c
 
T

Thunder Lion

Guest
but when will we get tuples and true user-defined types? :c
What does that mean?

And I'm glad it will be an update, in regards to the reading the array coordinates. That would be awesome to have vars that have multiple values. Even doing something like:
array_read_a(array[a,b])
Gives value (string/number).
Also would be nice to have 3D arrays....with this readability.
 
C

CptChuckles

Guest
A tuple is like an array where each element can be a different type, but mostly just two or three. And user-defined types would be like pure code-based structs or even classes, where you'd declare and define them in code and not need to create a new GM-object just to have a dedicated data structure to hold information, and they can even have functions in them. At the very least this would mean we could define things like vectors as a type rather than having to use multiple variables or even arrays to hold their components.
 
T

Thunder Lion

Guest
A tuple is like an array where each element can be a different type, but mostly just two or three. And user-defined types would be like pure code-based structs or even classes, where you'd declare and define them in code and not need to create a new GM-object just to have a dedicated data structure to hold information, and they can even have functions in them. At the very least this would mean we could define things like vectors as a type rather than having to use multiple variables or even arrays to hold their components.
That would be useful, even having a template to do this would be nice that auto codes it.
 

Joe Ellis

Member
A tuple is like an array where each element can be a different type, but mostly just two or three. And user-defined types would be like pure code-based structs or even classes, where you'd declare and define them in code and not need to create a new GM-object just to have a dedicated data structure to hold information, and they can even have functions in them. At the very least this would mean we could define things like vectors as a type rather than having to use multiple variables or even arrays to hold their components.
That is pretty much c++, building new possibilities, but I dont think this is gonna happen with gml, I dont wanna sound negative. I want it to happen but its not going to is it?
If you can do it, why not make a new gamemaker? :D
But really, a vector (vec3) is a 3 length array, in some ways gm's limited capabilities remind us of whats actually going on in the computer, all these classes and tuples are just fancy words for several arrays
 
C

CptChuckles

Guest
Edit: oops i did a blogpost

Without a doubt, there's always a way to look on the bright side of things, and one must choose to appreciate the experience of developing in GM or not, given its limitations. And it does sometimes give GM-dev a certain special flavor that us oldies have come to feel at home with. But there's limitations, and then there's limitations. I don't think anyone really forgets what a vector is data-wise, and if you want a real reminder of what's going on in the computer, you could always write in ASM. Aside from the sheer amount of lines it takes, one of the reasons people don't want to do that is because a resource-limited language doesn't make for a very good time building well-designed architecture, and eventually the spaghetti you have to make just to get things running can't be refactored enough to keep a project going. Almost everything that we need from structs and classes could be done in GM without them, but their absence doesn't really lend themselves to simplicity, but quite the opposite: one must make spaghetti out of GM resources (objects and scripts) to achieve results that a language with structs could achieve in a single code file. I see their absence also as a possible hindrance to new programmers: when they start programming in GML, the fact that they don't have this language resource means they start developing coding habits designed to compensate for that lack, and then there's an entirely new design philosophy they have to acclimate to when they begin in a mature language. And as for my own experience, it wasn't until I had learned object-oriented design principles in other languages that I became able to use GM as the object-oriented tool that it is. That's the sort of limitation that could be removed if GML gained structs or classes. You'd always have the old ways of doing things, but with the introduction of that, new developers could use and learn much more efficient design principles right in GML instead of having that obscured behind a resource tree--the very resources that you need those principles in order to use to their fullest potential.

TL;DR: i want things because of reasons
 
Top