Author Topic: Getting the name of a GUI button or a variable within it on click?  (Read 2117 times)

I'm attempting to make a Minesweeper game I can't figure out how to get either the name of a grid's square, or a variable within it when it's clicked.
I do know how I would detect variables from surrounding squares, but I need to get the one clicked first.

Code: [Select]
        for(%i=0;%i<%grid_width;%i++)
        {

                for(%j=0;%j<%grid_height;%j++)
                {

                        %pos = 1 + (%i*20) SPC 1 + (%j*20);

                        %grid = new GuiSwatchCtrl("Mine_Grid" SPC %i SPC %j)
                        {
                                profile = "GuiDefaultProfile";
                                horizSizing = "right";
                                vertSizing = "bottom";
                                position = %pos;
                                extent = "19 19";
                                minExtent = "19 19";
                                enabled = "1";
                                visible = "1";
                                clipToParent = "1";
                                color = "255 255 255 64";
                                mine = "0";
                                gridX = %i;
                                gridY = %j;
                        };
                        Mines_Area.add(%grid);

                }

        }

in the 2nd for loop, add
$MineArena::Mine[%i,%j]=%grid;
and refer to that when you want to get them

also, outer loop is rows and inner loop is columns, so %j would be X and %i would be Y

for detecting around, do:
function mineCheck(%x,%y)
{
   if($MineArena::Mine[%x,%y].mine)
      return -1;
   %count=0;
   for(%i=0;%i<3;%i++)
      for(%j=0;%j<3;%j++)
         if(%j!=1&&%x!=1)
            if(isObject($MineArena::Mine[%i+%x-1,%j+%y-1]))
               if($MineArena::Mine[%i+%x-1,%j+%y-1].mine)
                  %count++;
   return count;
}

-1 if it is a mine, count of mines, otherwise
« Last Edit: April 28, 2013, 05:51:29 PM by MARBLE MAN »

in the 2nd for loop, add
$MineArena::Mine[%i,%j]=%grid;
and refer to that when you want to get them

also, outer loop is rows and inner loop is columns, so %j would be X and %i would be Y
What about using buttons instead of swatches so you can actually click on them?
And then in your loop you can do this when creating the button:

command = "clickGrid(" @ %i @ ", " @ %j @ ");";

Then it will call clickGrid when you click on the button, with the arguments of column and width
I'm not on my pc so I can't tell you how to properly create buttons

What about using buttons instead of swatches so you can actually click on them?
And then in your loop you can do this when creating the button:

command = "clickGrid(" @ %i @ ", " @ %j @ ");";

Then it will call clickGrid when you click on the button, with the arguments of column and width
I'm not on my pc so I can't tell you how to properly create buttons
i was editing when you wrote that >.<

What about using buttons instead of swatches so you can actually click on them?
And then in your loop you can do this when creating the button:

command = "clickGrid(" @ %i @ ", " @ %j @ ");";

Then it will call clickGrid when you click on the button, with the arguments of column and width
I'm not on my pc so I can't tell you how to properly create buttons
I feel like an idiot, completely forgot you could still use %i and %j like that. thanks lol

And the swatches are so the grid is still visible once it's clicked.

hnnnn

new issue:
full code - https://bitbucket.org/TheBlackParrot/blockland-minesweeper-gui/src/2e7d973dc2c8c7d1a0f136b3bee470102d17a5c8/client.cs?at=master
Code: [Select]
// --attempt 2--
// if(%mine_count == 0 && %button_count != 0)
// {
//
// for(%i=0;%i<8;%i++)
// {
//
// %xc = getWord(%check[%i],0);
// %yc = getWord(%check[%i],1);
// Mines_clickGrid(%xc,%yc);
//
// }
//
// }

// --attempt 1---
// if(%mine_count == 0 && isObject("Mine_Grid_Button" SPC %check[%i]))
// {
//
// %xc = getWord(%check[%i],0);
// %yc = getWord(%check[%i],1);
// if(("Mine_Grid" SPC %check[%i]).mine == 0)
// {
//
// Mines_clickGrid(%xc,%yc);
//
// }
//
// if(isObject("Mine_Grid_Button" SPC %check[%i]))
// {
//
// ("Mine_Grid_Button" SPC %check[%i]).delete();
//
// }
//
// ("Mine_Grid_Button" SPC %x SPC %y).delete();
//
// }
//
// }
I'm trying to do the same command to the surrounding sqaures that also have 0 mines surrounding them, but both of those attempts at coding it just sends BL into an endless loop.
It seems like it would work that way but apparently not. :x

I'd also really like to keep it GUI-based rather then sending everything to their own variable.

("Mine_Grid_Button" SPC %x SPC %y).delete();


You cannot do that
Either add them to a global variable and then do $MineGridButton[%x, %y].delete(); or do eval("Mine_Grid_Button" @ %x @ "_" @ %y @ ".delete();");

No, it's easier than that.

Just do this:
Code: [Select]
%button = "Mine_Grid_Button_" @ %x @ "_" @ %y;
%button.delete();

("Mine_Grid_Button" SPC %x SPC %y).delete();


You cannot do that
Either add them to a global variable and then do $MineGridButton[%x, %y].delete(); or do eval("Mine_Grid_Button" @ %x @ "_" @ %y @ ".delete();");
If you go and look at the addon and it's code, it actually worked fine.

So what function is going wrong at the moment?

So what function is going wrong at the moment?
Nothing, it's all working.


unlocked so you'll get off my ass about it.

[im g width=1000 height=448]https://dl.dropboxusercontent.com/u/27975145/2013-05-05-172643_1440x900_scrot.png[/img]
unlocked so you'll get off my ass about it.
LOL