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

Username:   Password: 
 RegisterRegister   
 Classes in a module
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Lucas




PostPosted: Sat May 07, 2011 10:14 am   Post subject: Classes in a module

What is it you are trying to achieve?
I made a class for making buttons, and i want to put it in a module. Problem is I get an error when i make a new class, it says that its read only and cannot be "new"ed. How can I avoid this?

Turing:

module Stuff
    import Mouse
    export Buttons
    % Creates a button!
    class Buttons
        export Initialize, Clicked, Drawbutton
        % design variables
        var x1, y1, x2, y2 : int
        var text : string
        var txtclr : int
        var clrreg, clrover, clrpressed : int
        var clr : int
        % function variables
        var over : boolean := false
        var pressed : boolean := false
        var mx, my, bnum : int
        const font := Font.New ("Impact:18")
        % make the button, set variables
        proc Initialize (x1_, y1_, x2_, y2_ : int, text_ : string, txtclr_, clrreg_, clrover_, clrpressed_ : int)
            x1 := x1_
            y1 := y1_
            x2 := x2_
            y2 := y2_
            text := text_
            txtclr := txtclr_
            clrreg := clrreg_
            clrover := clrover_
            clrpressed := clrpressed_
            clr := clrreg
        end Initialize
        % check to see if the button is clicked, sets colors
        fcn Clicked : boolean
            mousewhere (mx, my, bnum)
            if mx >= x1 and mx <= x2 and my >= y1 and my <= y2 then
                over := true
                clr := clrover
                if bnum > 0 then % if the button is clicked
                    pressed := true
                    clr := clrpressed
                end if
                if bnum = 0 and pressed = true then
                    pressed := false
                    clr := clrreg
                    result true
                end if
            else
                clr := clrreg
            end if
            result false
        end Clicked
        % Draws the button
        proc Drawbutton
            var x, y : int
            Draw.FillBox (x1, y1, x2, y2, clr)
            x := round (((x2 - x1) / 2) + x1 - ((length (text) / 2) * 12))
            y := round (((y2 - y1) / 2) + y1 - 7)
            Font.Draw (text, x, y, font, txtclr)
        end Drawbutton
    end Buttons
end Stuff

var my_button : ^Stuff.Buttons
new Stuff.Buttons, my_button

Stuff.my_button -> Initialize (100, 100, 300, 200, "Im awsome", 42, 24, 26, 20)

loop
    if my_button -> Clicked = true then
        put "button is clicked"
    end if
    my_button -> Drawbutton
    delay (5)
    View.Update
end loop



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
chrisbrown




PostPosted: Sat May 07, 2011 11:35 am   Post subject: Re: Classes in a module

From the doc for Module:
Quote:
Procedures, functions, variables, constants and types can be exported; modules, monitors or classes cannot be exported.


I'd suggest moving the Button class to a separate file and importing it into the main program.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: