I am new to Win32::GUI and I am in the process of designing a game known as KENO. (I didn't pick it, it was a engineering expo that I can no longer enter in...) But anyways, I am making 80 buttons that when clicked will push the value they represent into the array so that I can later check to see if they guessed right. The problem is that the subroutine goes before being clicked. It is probably a basic syntax error, but I am either blind or just stupid...

Here is the important parts of my code:

#!/usr/bin/perl use Win32::GUI(); # Perl module for access to Windows <API functions @chosen; $main = Win32::GUI::Window->new( -name => 'Main', #name of the window, use for events -width => 675, -height => 600, -text => 'Keno', #title of window -minsize => [675, 600], -dialogui => 1 #contorls special keyboard handling ); ########Controls#################################### # 80 Buttons... Probably better and much more efficient #way... # The subroutine under "-onClick => &Button_Click(x)" is #executing be +fore the app. even shows up #basically I have 80 similar buttons $Button1= Win32::GUI::Button->new(-parent => $main, -pushlike => 1, -n +ame => Button1, -text => '1', -onClick => &Button_Click(1),-height => + 50, -width => 50, -pos => [15, 55],); $main->Show(); #By default windows are hidden, so make + #it visible... Win32::GUI::Dialog(); #start a Windows message loop, to + #get user interaction #######-Event Handlers################################ sub Main_Terminate{ -1; #Terminates loop }; sub Button_Click{ my $arg = $_[0]; #my $size = @chosen; unless( @chosen[9] ) { print "$arg was choosen\n"; push (@chosen, $ar +g); #my $message = Win32::MsgBox("$arg was choosen", 0, "$arg was choosen +"); } else { print "To many numbers chosen\n";} };

P.S. As you can tell from my profile, I am new to perlmonks. And sorry about the formatting, I had some trouble... (mostly laziness)

Thanks,
stringplayer92


In reply to Subroutines not working right by stringplayer92

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.