Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 GUI buttons
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
richcash




PostPosted: Wed Jun 14, 2006 6:45 pm   Post subject: GUI buttons

If I make a button and call to a procedure with a parameter it doesn't work. For example :
code:
var button := GUI.CreateButton (0, 0, 0, "button", do (1))

Why can't I do this?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Jun 14, 2006 6:51 pm   Post subject: (No subject)

GUI module passes a reference to the function, doesn't actually make a call to the function.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Ninja




PostPosted: Wed Jun 14, 2006 6:55 pm   Post subject: (No subject)

Tony wrote:
GUI module passes a reference to the function, doesn't actually make a call to the function.


Yep. for example look at this code, this is from the turing manual:
code:

import GUI
       
        procedure DrawRandomCircle
            var r : int := Rand.Int (20, 50)
            var x : int := Rand.Int (r, maxx - r)
            var y : int := Rand.Int (r, maxy - r)
            var c : int := Rand.Int (0, maxcolor)
            Draw.FillOval (x, y, r, r, c)
            % In case we drew over the buttons, redraw them.
            GUI.Refresh
        end DrawRandomCircle
       
        View.Set ("graphics:300;200,nobuttonbar ")
        var draw : int := GUI.CreateButtonFull (50, 10, 0, "Draw Circle",
            DrawRandomCircle, 0, '^D', true)
        var quitBtn : int := GUI.CreateButton (200, 10, 0, "Quit", GUI.Quit)
        loop
            exit when GUI.ProcessEvent
        end loop

when you are making a button using the GUI module, you have to specify what function to pass reference to. In this program the first button is passing reference to the DrawRandomCircle procedure, but the other one uses the built in function the GUI.Quit for which you dont have to write a separate procedure.
richcash




PostPosted: Wed Jun 14, 2006 7:02 pm   Post subject: (No subject)

Oh yeah, that's right, thx. That's kind of inconvenient, but so is the whole GUI module!
Tony




PostPosted: Wed Jun 14, 2006 7:06 pm   Post subject: (No subject)

you could always hack away at the GUI module's code to get it to work for you. Remember that you'd need to include all of the files with source to compile properly.

What are you trying to do anyways? It sounds like you're trying to generate a load of buttons inside some loop.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
richcash




PostPosted: Wed Jun 14, 2006 8:44 pm   Post subject: (No subject)

Oh, I just wanted the button to call my draw procedure for a card game but I wanted to make the same procedure for both the cpu and the user. So, draw (1) gives the user a new card in his hand, and draw (2) gives the computer a new card. I only want the 'Draw' button I create to give the user a card. Obviously I can work around it, I just like doing things really efficiently!
Tony




PostPosted: Wed Jun 14, 2006 8:52 pm   Post subject: (No subject)

what you can do is set up a mini-function for the button
code:

var button := GUI.CreateButton (0, 0, 0, "button", mini_fnc() )

where
code:

func mini_fnc()
   %call draw on user's behalf
   draw(1)
end mini_fnc
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
richcash




PostPosted: Wed Jun 14, 2006 8:59 pm   Post subject: (No subject)

Could you further explain this technique because I know you can't call functions as the action for a button? Or did you mean to make mini_fcn a proc?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Jun 14, 2006 9:02 pm   Post subject: (No subject)

a procedure is a void function (does not return results). And yes, I meant a procedure.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
richcash




PostPosted: Wed Jun 14, 2006 9:07 pm   Post subject: (No subject)

Yeah, I know a procedure is really a function. I never thought of this, just calling my proc with parameters in another one for the button. Thanks for the help!!!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: