• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

to Count blocks in a row (not quite)

mafon2

Member
Ok, I'm trying to make a simple stacking game, but every simple thing you don't notice requires a code explanation for the machine.

So I want to check the preasure on blocks, mostly to know which one is the highest one, so you can grab it, but I'm also thinking it could be useful to make fragile blocks or preasure buttons / scales, that sort of thing (1 block = 1 preasure).

I was dancing with a tambouring for quite a vile (my usual practice) and I've got some interesting results sometimes (pretty close, but no cigar). For now code looks like this:

Create

Code:
preasure = 0; // To know how much blocks lie on it
preasure_check = 0; // to stop/reset preasure checking... it was used more frequently, but it's lost the purpose.
Step

Code:
if (preasure_check = 0 )
    {
    if (place_meeting(x,y-gridSize, obj_block))
        {
        preasure = other.preasure + 1;
        }   

    if (!place_meeting(x,y-gridSize, obj_block))
        {
        preasure = 0;
        }
    }


It creates columns of 1s with 0s on top and it's ok, but after I move some of them it produces
nonsensical results.

Works ok for the grabbing part, but it's not enough for preasure measuring.

...

Any help will be appreciated.
 
Last edited:

Perseus

Not Medusa
Forum Staff
Moderator
The other keyword has no meaning outside a with statement or a Collision event. The place_meeting function is not the same as a Collision event, so other is not actually doing what you think it should do.

Number of block instances above a certain block can be calculated by something like this:

Code:
var not_empty = true,
    _y = y - gridSize;
while (not_empty) {
    if (place_meeting(x, _y, obj_block)) {
        number += 1;
        _y -= gridSize;
    } else {
         not_empty = false;
    }
}
That might not be the best way to handle it. If it isn't too late, you should handle the gameplay via a DS grid. You can then mark cells as occupied or unoccupied. Getting the number of occupied cells that you're under without interruption in between should be fairly easy.
 

mafon2

Member
Thank you! *scratches head* Looks not quite like I've imagined. To be frank, I didn't understand a thing.

It's not too late. But it's a little game I want to finish and move on.

I changed code to

Code:
var inst_below = instance_position(x, y + gridSize, obj_block);
if (instance_exists(inst_below) && inst_below.preasure_check = 0)
{
   inst_below.preasure = preasure + 1;
   inst_below.preasure_check = 1;
}
it works ok. Some quirks during stacking, but it's because of flimsy lifting.



The strange thing: it refreshes only if moving block (obj_COW) hits the left wall... only god knows why, probably it favours cows. Yes, the collision between blocks refreshes preasure_check, but I was trying to add refresh to alarms, steps and other stuff, but only this yellow block hitting the wall does the trick. Ok, it'll be a part of interface :p.
 
Last edited:

mafon2

Member
Bonus question: I have parrent instance «obj_block» (for all solids), it's child «obj_movable_block» (for all movable solids) and it's "grandchild" «obj_glass».

obj_glass behaves as it's parent – obj_movable_block, but when I add any step event, even empty one, it loses all it's properties. It's engine restriction, isn't it?

SOLVED: event_inherited();
 
Last edited:
Top