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

Username:   Password: 
 RegisterRegister   
 Combining Buttons With Procedures that Take Inputs
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Drake




PostPosted: Tue May 17, 2005 12:32 pm   Post subject: Combining Buttons With Procedures that Take Inputs

I've been having a bit of trouble with combining buttons with procedures that accept inputs. Making buttons is no problem. Making procedures is no problem. Making buttons that call procedures is no problem. It's when the procedures require an input that it is a problem. For example:

LabelSkillLevel (number : int)
~~~~~
end LabelSkillLevel

GUI.CreateButton (x, ... , LabelSkillLevel(1))

This is pretty much what I'm using for my program. The error that Turing gives to me is:
'LabelSkillLevel' is a procedure call and hence does not return a value.

I've tried even changing LabelSkillLevel to a process, and it gave me the exact same error.

I've looked around a bit and haven't been able to find anything that really helps me. The help files do say that I call a procedure but they say nothing about procedures that require inputs. The help files on procedures do show them using ones with inputs and I know the procedure I have made works correctly. The button works just fine if the procedure accepts no inputs.

If I am in error about there not being a post about this earlier or about this belonging here, let me know and I'll delete it.
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Tue May 17, 2005 1:30 pm   Post subject: (No subject)

LabelSkillLevel (number : int)
~~~~~
end LabelSkillLevel

GUI.CreateButton (x, ... , LabelSkillLevel(1))

So this is basically what you have. Ok, number represents whatever value comes out of the button, and you make number equal to whatever variable that you would want equal to that. Have you tried taking out the (1)? There's no need for it. Try that.
Cervantes




PostPosted: Tue May 17, 2005 6:42 pm   Post subject: (No subject)

I think what you are getting at is that turing's GUI cannot accept procedures with parameters (which is entirely stupid). To fix this, maybe you'll have to edit the GUI source code. I've never tried this, mind you, so I cannot comment on how difficult that might be. I can tell you, however, that you can make your own buttons rather easily. If you know how to use procedures, flexible arrays, records, and mouse input, you can make buttons for your program easily enough. If you know how to use classes, you make your own button class, and then therefore use your own buttons in any of your programs.

I will outline the basic button class:

code:

class BUTTON
    export INIT, changeLabel, show, hide, clicked, draw
    var button :
        record
            %fields
        end record

    proc INIT ( /*lots of parameters*/)
        %set button fields to the parameters the user inputs
    end INIT

    proc changeLabel (text : string)
        button.label_.text := text
    end changeLabel

    proc show
        button.visible := true
    end show
    proc hide
        button.visible := false
    end hide

    fcn clicked : boolean
        %code to determine whether the button has been clicked
    end clicked
   
    proc draw
        Draw.FillBox (button.x1, button.y1, button.x2, button.y2, button.clr)
        Font.Draw (button.label_.text, button.label_.x, button.label_.y, button.label_.font, button.label_.clr
    end draw
end BUTTON


Then, you can create a flexible array of pointers to the button class. To get them to do anything, you'd have to go (inside your main loop):
code:

if button (1) -> clicked then
    %do this
end if
if button (2) -> clicked then
    ...
end if

It might not be as nice to code your main program with, but it's by far more versatile. And if you hate the code structure that turing's GUI makes you go through as much as I do, you'll probably find this structure style nicer.
If you don't know what classes are, maybe just make some procedures right inside your program. If you don't know much about procedures, flexible arrays, records, or mouse input, ignore my entire post. Laughing

Cervantes
StarGateSG-1




PostPosted: Wed May 18, 2005 7:31 am   Post subject: (No subject)

Hey I was reading this post I think I will go itno the source code and see if I can play with that. Very Happy
Drake




PostPosted: Wed May 18, 2005 12:16 pm   Post subject: (No subject)

jamonathin wrote:
LabelSkillLevel (number : int)
~~~~~
end LabelSkillLevel

GUI.CreateButton (x, ... , LabelSkillLevel(1))

So this is basically what you have. Ok, number represents whatever value comes out of the button, and you make number equal to whatever variable that you would want equal to that. Have you tried taking out the (1)? There's no need for it. Try that.


That wouldn't work. Sorry, but I guess I didn't explain myself well enough when I first posted on here. Embarassed I currently have pseudo-buttons working. Essentially, I drew boxes and checked to see if the mouse button equaled 1 when the mousex and mousey were within the location of the box. I want to change it to regular buttons because that would take up -lots- of less space. The reason I need to have hte number there is becasue I want to have three different buttons displayed at the same time, depending on which you push calls the same procedure but does something different depending on the number attached to the procedure name. If it was just two buttons, I wouldn't bother with an input because I could just check for if it was true or not; it would be one or the other button that was pressed so act accordingly. But there are three so I need to very definetly define what button was pressed to make the sure the right thing happens. If that doesn't make sense, sorry. I'm obviously not very good at explaining things.
Drake




PostPosted: Wed Jun 08, 2005 8:15 pm   Post subject: Button Source Code

Stargate, I'm guessing you didn't come up with anything for the source code? I found a way around the problem (I created a new procedure for each button, -huge- waste of space) temporarily, but I've run up into it again and I am sure that this time I can't go around it.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: