• 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!

What data structures to use to store 3 values of 1 instance

A

AFD456

Guest
Hello everyone,
I'm trying to recreate Guess the Logo game(more precisely part of it so far) https://play.google.com/store/apps/details?id=com.msi.logogame.
So I create 4 instances (of object oABC which contains letters - 1 letter = 1 instance) at the start of the game. When I click on one of them it moves to different position. I want to be able to move it to original position If I click on it for the second time.
Here is my (simplified) code:

oABC_Create:
abc_id = ds_list_create()
abc_x = ds_list_create()
abc_y = ds_list_create()

oABC_Left_Pressed:
if condition....//click on it for the first time
{
x = new position....
y = new position....
ds_list_add(abc_x,x)
ds_list_add(abc_y,y)
ds_list_add(abc_id,id)
}
else if condition.... //if I click on it for the second time
{
//I try to compare id of the instance I clicked on for second time with every id stored in abc_id data structure
//and if it matches, the code finds original x and y (temp_x,temp_y) values of the instance and write them to //x and y;
for(var i=0;i<4;i++)
{
temp_id = ds_list_find_value(abc_id,i)
temp_x = ds_list_find_value(abc_x,i)
temp_y = ds_list_find_value(abc_y,i)
if temp_id == id
{
x = temp_x
y = temp_y
exit
}
}
I hope I made myself clear.
Thank you for your time and answers! Have a nice day.
 
So, what's the problem you are having? You told us what you want to do...is the problem that your code is not moving them back to the original position?

If so, I think the problem is here:

Code:
oABC_Left_Pressed:
if condition....//click on it for the first time
{
    x = new position....
    y = new position....
    ds_list_add(abc_x,x)
    ds_list_add(abc_y,y)
    ds_list_add(abc_id,id)
}
You are moving it to a new position, *then* you are saving the objects position.

Don't you want to be saving the objects original position first, then moving it?

Like so:
Code:
oABC_Left_Pressed:
if condition....//click on it for the first time
{
    ds_list_add(abc_x,x)
    ds_list_add(abc_y,y)
    ds_list_add(abc_id,id)

    x = new position....
    y = new position....
}
Also, use code tags to make your code easier to read (as follows, without the spaces):

[ c o d e ]
...
[ / c o d e ]
 
A

AFD456

Guest
So, what's the problem you are having? You told us what you want to do...is the problem that your code is not moving them back to the original position?

If so, I think the problem is here:

Code:
oABC_Left_Pressed:
if condition....//click on it for the first time
{
    x = new position....
    y = new position....
    ds_list_add(abc_x,x)
    ds_list_add(abc_y,y)
    ds_list_add(abc_id,id)
}
You are moving it to a new position, *then* you are saving the objects position.

Don't you want to be saving the objects original position first, then moving it?

[ c o d e ]
...
[ / c o d e ]
I tried this and it still doesnt work:
Code:
    ds_list_add(abc_x,x)
    ds_list_add(abc_y,y)
    ds_list_add(abc_id,id)
    x = new position....
    y = new position....
 
A

AFD456

Guest
Well I just put this in to my code and it works just great:)
x = xstart
 

NicoFIDI

Member
The difference it's that you dont need to use a specific order or define constants that holds the index, because you acces the data inside the map with a completly readable string.
And you can make It so you have the id on the key followed by the value.
But since you find a one line solution then never mind this
 
Top