GML [SOLVED) Stacking game?

W

Wyverdan

Guest
Hi I'm having a little trouble finding the right (and working) solution for a "stacking game".

Basically I have some dragable blocks that needs to be stacked in the correct order. These blocks are taking from an array. The first block is Hydrogen (H) with a value of 1, the second is Helium (He) with a value of 2, the third is Lithium (Li) with a value of 3 and so forth.
10 element blocks are chosen and then I need to stack them in a grid, heaviest first from the bottom.

My question is how would that work? How do I get Gamemaker to know, what the heaviest of the 10 elements available is?
And how do I make it know that in that particular instance, which element is the 9th heaviest and thus go on top of number 10?
 

TailBit

Member
If all of them have the same parent object, like obj_block .. and maybe 2 variables:
Code:
value = 0;
stacked = false;
when you then try to drop it on the stack, or click it, then you can run a check:
Code:
var n = 0; // we set a low number

with(obj_block){ // tell all block objects

   if(!stacked){ // if it haven't been stacked
      if(value > n) n = value; // if its value is higher, overwrite the low value
  }

}

// n will now contain the highest number that isn't stacked .. and you can allow the one you dropped to be stacked if it is equal to this number
if( n = value ) stacked = true;
for test you could have all stacked move to the side if pressed, step event:
Code:
if( stacked ) x=0;
 
W

Wyverdan

Guest
If all of them have the same parent object, like obj_block .. and maybe 2 variables:
Code:
value = 0;
stacked = false;
when you then try to drop it on the stack, or click it, then you can run a check:
Code:
var n = 0; // we set a low number

with(obj_block){ // tell all block objects

   if(!stacked){ // if it haven't been stacked
      if(value > n) n = value; // if its value is higher, overwrite the low value
  }

}

// n will now contain the highest number that isn't stacked .. and you can allow the one you dropped to be stacked if it is equal to this number
if( n = value ) stacked = true;
for test you could have all stacked move to the side if pressed, step event:
Code:
if( stacked ) x=0;
Thanks. I think this might be what I'm looking for. I have however run in to some other issues, but thanks a lot for this, I really appreciate it.
 
Top