for($i = 0; $i < 9; $i++) {
$sub[$i] = $i;
$board[$i] = $mw->new_ttk__button(-textvariable => \$state[$i],
-command => sub {btnPressed($sub[$i]);});
$board[$i]->g_grid(-row => int($i / 3) + 1,
-column => ($i % 3) + 1,
-sticky => "nsew",
-ipadx => 5,
-ipady => 5);
}
sub btnPressed($) {
$btn = $_[0];
if ($turns % 2 == 1) {
$state[$btn] = "O";
}
else {
$state[$btn] = "X";
}
$board[$btn]->state("disabled");
$turns += 1;
}
that code is part of my simple implementation of tic tac toe. my problem is that when i pass $sub[$i] to btnpressed(), it doesn't work. if i say print @_ in the subroutine, it does not contain anything, however print @sub produces 012345678 as it should. what's the problem?
$sub[$i] = $i;
$board[$i] = $mw->new_ttk__button(-textvariable => \$state[$i],
-command => sub {btnPressed($sub[$i]);});
$board[$i]->g_grid(-row => int($i / 3) + 1,
-column => ($i % 3) + 1,
-sticky => "nsew",
-ipadx => 5,
-ipady => 5);
}
sub btnPressed($) {
$btn = $_[0];
if ($turns % 2 == 1) {
$state[$btn] = "O";
}
else {
$state[$btn] = "X";
}
$board[$btn]->state("disabled");
$turns += 1;
}
that code is part of my simple implementation of tic tac toe. my problem is that when i pass $sub[$i] to btnpressed(), it doesn't work. if i say print @_ in the subroutine, it does not contain anything, however print @sub produces 012345678 as it should. what's the problem?