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

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




PostPosted: Sun May 08, 2005 11:38 am   Post subject: help with buttons

can some1 plz help.....i cant get my buttons to workout rite...when u click stop on the second one it doesnt work and when u click next on the second one it does not move onto the third one
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Sun May 08, 2005 1:17 pm   Post subject: (No subject)

Here it is, just press and hold for a second to get to the next step. The programming isn't pretty (that's your job) I just fixed it for you, now just organize it.

And for the record, process and proc's are very different. (one works)
Turing:

setscreen ("graphics")
var font1 : int := Font.New ("Arial:12")
var finished1, finished2, stopall : boolean := false
var mouse_x, mouse_y, button : int


process DoMusic
    loop
        exit when finished1 or finished2 or stopall
        Music.PlayFile ("123.MP3")
    end loop
end DoMusic

procedure bar
    drawbox (0, 0, 50, 25, black)
    Font.Draw ("Stop", 10, 6, font1, 16)
    drawline (0, 30, maxx, 30, black)
    drawbox (590, 0, 639, 25, black)
    Font.Draw ("Next", 598, 6, font1, 16)
end bar

proc one_theme
    var touch, cont : int := 0
    colorback (10)
    cls
    bar
    loop
        mousewhere (mouse_x, mouse_y, button)
        locate (1, 1)
        put mouse_x, " ", mouse_y ..
        if (button = 1) and (mouse_x > 0) and (mouse_x < 50)
                and (mouse_y > 0) and (mouse_y < 25) then
            stopall := true % set finished to true
            Music.PlayFileStop % stop the music
            exit
        elsif (button = 1) and (mouse_x > 590) and (mouse_x < 639)
                and (mouse_y > 0) and (mouse_y < 25) then
            finished1 := true
            cls
            bar
            exit
        end if
        if (touch = 0) then
            drawline (640 div 2, 480 div 2, Rand.Int (1, 640), Rand.Int (30, 480), red)
            cont += 1
            if cont = 50000 then
                touch := 1
                cont := 0
            end if
        elsif (touch = 1) then
            drawline (640 div 2, 480 div 2, Rand.Int (1, 640), Rand.Int (30, 480), green)
            cont += 1
            if cont = 50000 then
                touch := 2
                cont := 0
            end if
        elsif (touch = 2) then
            drawline (640 div 2, 480 div 2, Rand.Int (1, 640), Rand.Int (30, 480), blue)
            cont += 1
            if cont = 50000 then
                touch := 3
                cont := 0
            end if
        elsif (touch = 3) then
            drawline (640 div 2, 480 div 2, Rand.Int (1, 640), Rand.Int (30, 480), yellow)
            cont += 1
            if cont = 50000 then
                touch := 0
                cont := 0
            end if
        end if
    end loop
end one_theme
proc second_theme
    colorback (yellow)
    cls
    bar
    drawfillbox (0, 40, 640, 490, 43)
    delay (500)
    loop
        mousewhere (mouse_x, mouse_y, button)
        if (button = 1) and (mouse_x > 0) and (mouse_x < 50)
                and (mouse_y > 0) and (mouse_y < 25) then
            stopall := true % set finished to true
            Music.PlayFileStop % stop the music
            exit
        elsif (button = 1) and (mouse_x > 590) and (mouse_x < 639)
                and (mouse_y > 0) and (mouse_y < 25) then
            finished2 := true
            cls
            bar
            exit
        end if
        drawfilloval (400, 200, 80, 80, white)
        drawoval (400, 200, 80, 80, black)
        drawfilloval (450, 200, 30, 30, black)
        for c : 0 .. 200
            drawfillbox (680 - c, 180, 680 - c, 210, 89)
            delay (5)
        end for
        drawfilloval (490, 250, 5, 5, blue)
        drawfilloval (490, 150, 5, 5, blue)
        drawfilloval (500, 130, 5, 5, blue)
        drawfilloval (500, 280, 5, 5, blue)
        drawfilloval (510, 265, 5, 5, blue)
        drawfilloval (510, 140, 5, 5, blue)
        for c : 0 .. 200
            drawfillbox (680 - 200 + c, 180, 680 - 200 + c, 210, 43)         %....finger
            delay (2)
        end for
        drawfilloval (490, 250, 5, 5, 43)
        drawfilloval (490, 150, 5, 5, 43)
        drawfilloval (500, 130, 5, 5, 43)
        drawfilloval (500, 280, 5, 5, 43)
        drawfilloval (510, 265, 5, 5, 43)
        drawfilloval (510, 140, 5, 5, 43)
    end loop
end second_theme

proc third_theme
    colorback (grey)
    cls
    bar
    delay (500)
    loop
        mousewhere (mouse_x, mouse_y, button)
        if (button = 1) and (mouse_x > 0) and (mouse_x < 50)
                and (mouse_y > 0) and (mouse_y < 25) then
            Music.PlayFileStop             % stop the music
            exit
        elsif (button = 1) and (mouse_x > 590) and (mouse_x < 639)
                and (mouse_y > 0) and (mouse_y < 25) then
            exit
        end if
        Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (30, maxx)), white)
        Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (30, maxx)), green)
        Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (30, maxx)), 144)
    end loop
end third_theme

fork DoMusic

%i think procedure and process are the same, i'm not sure : wrong - jamonathin
one_theme
if stopall = false then
    second_theme
end if
if stopall = false then
    third_theme
end if
recyclebin123




PostPosted: Sun May 08, 2005 2:32 pm   Post subject: (No subject)

wow..thanks a bunch =)......also i got another problem....when u click next on the last theme it ends...i need it to loop back to the first theme which i do not know how..also i just remembered that i needed a different music for each theme which i also do not know how to add in
mercuryy




PostPosted: Sun May 08, 2005 4:25 pm   Post subject: (No subject)

I am doing a program that has the similar structure. I want to put a menu in front of the first screensaver. and is there anyway that i can use the mouse to click back to the menu after I view all the screensaver?
jamonathin




PostPosted: Sun May 08, 2005 7:13 pm   Post subject: (No subject)

This should answer all of your questions. This program can be easily edited, so make more slides and add them on. Idea
Turing:

setscreen ("graphics:500;400,nobuttonbar,position:center;center,offscreenonly,title:Remember - Jamonathin Made This . . .    :P")
colorback (black)
cls
var mx, my, mz : int %Mouse Variables
var a, b, c, d : array 1 .. 4 of int
for i : 1 .. 4
    a (i) := 100 + ((i - 1) * 80) %Lower Left Hand Corner Of Button - X
    b (i) := 20 %Lower Left Hand Corner Of Button - Y
    c (i) := 150 + ((i - 1) * 80) %Top Right Hand Corner Of Button - X
    d (i) := 50 %Top Right Hand Corner Of Button - Y
end for
var font : int := Font.New ("Comic Sans MS:12:bold")
var text : array 1 .. 4 of string := init ("Back", "Pause", "Exit", "Next")
var text_x : array 1 .. 4 of int := init (105, 185, 270, 345)

%Used To Determine Which Screen Saver is Shown
var selection : int := 1
%Used To Determine Which Option Is Made
var option : int := 0
%Used To Tell Computer The Max Amount Of Screen Savers
var maxslide : int := 3

% SCREEN SAVER 1
procedure screensaver_1
    drawline (maxx div 2, maxy div 2, Rand.Int (0, maxx), Rand.Int (55, maxy), Rand.Int (1, maxcolor))
end screensaver_1

%SCREEN SAVER 2
var box : int := maxx - 50
var q : int := -1
procedure screensaver_2
    drawfillbox (0, 55, maxx, maxy, black) %Instead of doing cls
    drawfilloval (100, 200, 80, 80, white) %The Eye (you made it so figure it out :P)
    drawoval (100, 200, 80, 80, black)
    drawfilloval (150, 200, 30, 30, black)
    if box - 20 <= 180 or box > maxx - 50 then %Reversing Direction Of Finger
        q *= -1
    end if
    box += q * 3 %Always Moving Finger
    drawfillbox (box, 185, box + 200, 215, 89) %Drawing Finger/Hand
    drawfillbox (box + 120, 125, maxx + 5, 225, 89)
    drawfilloval (box + 120, 170, 15, 15, 89)
    drawfilloval (box + 120, 140, 15, 15, 89)
    drawfilloval (box + 120, 210, 15, 15, 89)
    drawfilloval (box, 200, 20, 15, 89)
    if box <= 210 then %Drawing Tears
        drawfilloval (190, 250, 5, 5, brightblue)
        drawfilloval (190, 150, 5, 5, brightblue)
        drawfilloval (200, 130, 5, 5, brightblue)
        drawfilloval (200, 280, 5, 5, brightblue)
        drawfilloval (210, 265, 5, 5, brightblue)
        drawfilloval (210, 140, 5, 5, brightblue)
    end if
    View.Update
end screensaver_2

%SCREEN SAVER 3
procedure screensaver_3
    Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (55, maxy)), white)
    Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (55, maxy)), green)
    Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (55, maxy)), 144)
    View.Update
end screensaver_3

%MAIN LOOP
loop
    mousewhere (mx, my, mz)
    %Screen Saver Selection
    if selection > 0 then
        drawfillbox (0, 55, maxx, maxy, black)
        selection *= -1
    end if
    %Screen Saver 2
    if selection = -1 then
        screensaver_1
        delay (5)
    end if
    %Screen Saver 2
    if selection = -2 then
        screensaver_2
        delay (10)
    end if
    %Screen Saver 3
    if selection = -3 then
        screensaver_3
        delay (5)
    end if
    %Finding out Which Option Is Made
    for i : 1 .. 4
        Font.Draw (text (i), text_x (i), 30, font, 10) %Drawing All 4 texts
        drawbox (a (i), b (i), c (i), d (i), white) %Drawing All 4 Boxes
        if mx >= a (i) and my >= b (i) and mx <= c (i) and my <= d (i) then
            drawbox (a (i), b (i), c (i), d (i), 12) %Drawing Selected Box
            Font.Draw (text (i), text_x (i), 30, font, yellow) %Drawing Selected Font
            if mz = 1 then
                option := i %Making Option Equal To What The User Has Selected
            end if
        end if
        View.Update
    end for
    %Back Button
    if option = 1 then
        selection *= -1 %Changing Back From -'s to +'s (don't ask why I even made negatives, I'm Wierd)
        if selection = 1 then
            selection := maxslide %Changing From 1st Slide to Last
        else
            selection -= 1
        end if
        option := 0 %Making The Option Blank
        delay (500)
    end if
    %Pause Button
    if option = 2 then
        var newfont : int := Font.New ("Comic Sans MS:20:bold")
        var pic : int := Pic.New (0, 55, maxx, maxy) %Drawing What The Program Drew Last
        Font.Draw ("Press Anything To Continue", 75, 200, newfont, yellow)
        View.Update
        delay (500)
        loop
            mousewhere (mx, my, mz)
            exit when hasch or mz = 1 %Looping Until We Continue
        end loop
        Pic.Draw (pic, 0, 55, picCopy) %Drawing What We Left Off With
        option := 0 %Making The Option Blank
    end if
    %Exit button
    if option = 3 then
        exit %Finished, Add Something Special After Loop :P
    end if
    %Next Button
    if option = 4 then
        selection *= -1 %Changing Back From -'s to +'s (don't ask why I even made negatives, I'm Wierd)
        if selection = maxslide then %Going From Lasr Slide to 1st
            selection := 1
        else
            selection += 1
        end if
        option := 0 %Making The Option Blank
        delay (500)
    end if
end loop
recyclebin123




PostPosted: Sun May 08, 2005 8:22 pm   Post subject: (No subject)

WOW! thanks i owe u one...lol Very Happy....hmmm one last question...i have to add 3 different musicfiles for each themes which i dont know where to and how to add them in...can u plz help me with this last problem and i will be extremely grateful
jamonathin




PostPosted: Mon May 09, 2005 9:58 am   Post subject: (No subject)

Try this out. I've never personally used Music for Background or anything, juss sfx so I've never had to worry about stopping it. I have no actaual music here to work with, but just try it out and play with it. The concept at least should be correct. Thinking
Turing:

setscreen ("graphics:500;400,nobuttonbar,position:center;center,offscreenonly,title:Remember - Jamonathin Made This . . .    ")
colorback (black)
cls
var mx, my, mz : int %Mouse Variables
var a, b, c, d : array 1 .. 4 of int
for i : 1 .. 4
    a (i) := 100 + ((i - 1) * 80) %Lower Left Hand Corner Of Button - X
    b (i) := 20 %Lower Left Hand Corner Of Button - Y
    c (i) := 150 + ((i - 1) * 80) %Top Right Hand Corner Of Button - X
    d (i) := 50 %Top Right Hand Corner Of Button - Y
end for
var font : int := Font.New ("Comic Sans MS:12:bold")
var text : array 1 .. 4 of string := init ("Back", "Pause", "Exit", "Next")
var text_x : array 1 .. 4 of int := init (105, 185, 270, 345)

%Used To Determine Which Screen Saver is Shown
var selection : int := 1
%Used To Determine Which Option Is Made
var option : int := 0
%Used To Tell Computer The Max Amount Of Screen Savers
var maxslide : int := 3
%Music
var song : array 1 .. 3 of string := init ("Song1.mp3", "Song2.mp3", "Song3.mp3")


% SCREEN SAVER 1
procedure screensaver_1
    drawline (maxx div 2, maxy div 2, Rand.Int (0, maxx), Rand.Int (55, maxy), Rand.Int (1, maxcolor))
end screensaver_1
process music
    loop
        if selection < 0 then
            Music.PlayFile (song (selection * -1))
        else
            Music.PlayFile (song (selection))
        end if
    end loop
end music
fork music

%SCREEN SAVER 2
var box : int := maxx - 50
var q : int := -1
procedure screensaver_2
    drawfillbox (0, 55, maxx, maxy, black)         %Instead of doing cls
    drawfilloval (100, 200, 80, 80, white)         %The Eye (you made it so figure it out )
    drawoval (100, 200, 80, 80, black)
    drawfilloval (150, 200, 30, 30, black)
    if box - 20 <= 180 or box > maxx - 50 then         %Reversing Direction Of Finger
        q *= -1
    end if
    box += q * 3         %Always Moving Finger
    drawfillbox (box, 185, box + 200, 215, 89)         %Drawing Finger/Hand
    drawfillbox (box + 120, 125, maxx + 5, 225, 89)
    drawfilloval (box + 120, 170, 15, 15, 89)
    drawfilloval (box + 120, 140, 15, 15, 89)
    drawfilloval (box + 120, 210, 15, 15, 89)
    drawfilloval (box, 200, 20, 15, 89)
    if box <= 210 then         %Drawing Tears
        drawfilloval (190, 250, 5, 5, brightblue)
        drawfilloval (190, 150, 5, 5, brightblue)
        drawfilloval (200, 130, 5, 5, brightblue)
        drawfilloval (200, 280, 5, 5, brightblue)
        drawfilloval (210, 265, 5, 5, brightblue)
        drawfilloval (210, 140, 5, 5, brightblue)
    end if
    View.Update
end screensaver_2

%SCREEN SAVER 3
procedure screensaver_3
    Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (55, maxy)), white)
    Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (55, maxy)), green)
    Draw.Dot ((Rand.Int (0, maxx)), (Rand.Int (55, maxy)), 144)
    View.Update
end screensaver_3

%MAIN LOOP
loop
    mousewhere (mx, my, mz)
    %Screen Saver Selection
    if selection > 0 then
        drawfillbox (0, 55, maxx, maxy, black)
        selection *= -1
    end if
    %Screen Saver 2
    if selection = -1 then
        screensaver_1
        delay (5)
    end if
    %Screen Saver 2
    if selection = -2 then
        screensaver_2
        delay (10)
    end if
    %Screen Saver 3
    if selection = -3 then
        screensaver_3
        delay (5)
    end if
    %Finding out Which Option Is Made
    for i : 1 .. 4
        Font.Draw (text (i), text_x (i), 30, font, 10)         %Drawing All 4 texts
        drawbox (a (i), b (i), c (i), d (i), white)         %Drawing All 4 Boxes
        if mx >= a (i) and my >= b (i) and mx <= c (i) and my <= d (i) then
            drawbox (a (i), b (i), c (i), d (i), 12)         %Drawing Selected Box
            Font.Draw (text (i), text_x (i), 30, font, yellow)         %Drawing Selected Font
            if mz = 1 then
                option := i         %Making Option Equal To What The User Has Selected
            end if
        end if
        View.Update
    end for
    %Back Button
    if option = 1 then
        selection *= -1         %Changing Back From -'s to +'s (don't ask why I even made negatives, I'm Wierd)
        Music.PlayFileStop
        if selection = 1 then
            selection := maxslide         %Changing From 1st Slide to Last
        else
            selection -= 1
        end if
        fork music
        option := 0         %Making The Option Blank
        delay (500)
    end if
    %Pause Button
    if option = 2 then
        var newfont : int := Font.New ("Comic Sans MS:20:bold")
        var pic : int := Pic.New (0, 55, maxx, maxy)         %Drawing What The Program Drew Last
        Font.Draw ("Press Anything To Continue", 75, 200, newfont, yellow)
        View.Update
        delay (500)
        loop
            mousewhere (mx, my, mz)
            exit when hasch or mz = 1         %Looping Until We Continue
        end loop
        Pic.Draw (pic, 0, 55, picCopy)         %Drawing What We Left Off With
        option := 0         %Making The Option Blank
    end if
    %Exit button
    if option = 3 then
        exit         %Finished, Add Something Special After Loop
    end if
    %Next Button
    if option = 4 then
        selection *= -1         %Changing Back From -'s to +'s (don't ask why I even made negatives, I'm Wierd)
        Music.PlayFileStop
        if selection = maxslide then         %Going From Lasr Slide to 1st
            selection := 1
        else
            selection += 1
        end if
        fork music
        option := 0         %Making The Option Blank
        delay (500)
    end if
end loop
mercuryy




PostPosted: Tue May 10, 2005 10:25 pm   Post subject: (No subject)

Humm. I treid to modify the program but it dosnt' work for some reason.
Instead of a screen saver. I tried to put text (e.g. put"Menu") inside the procedure. But the program output an never-ending loop. Why? How should I change it to make the first screen a menu instead?
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Wed May 11, 2005 5:45 am   Post subject: (No subject)

Well, if you make a new procedure, you're going to have to change some of the coding. For example, if you want this one (your menu) to be the first item, then you need to put it on selection:=1 and bump everything back one and make an if for screensaver_3 under selection = 4.
Turing:

    %Main Menu
    if selection = -1 then
        menu_selection %or w.e
        delay (5)
    end if
    %Screen Saver 1
    if selection = -2 then
        screensaver_1
        delay (10)
    end if
    %Screen Saver 2
    if selection = -3 then
        screensaver_2
        delay (5)
    end if
    %Screen Saver 4
    if selection = -4 then
        screensaver_3
        delay (5)
    end if

Now you have to change maxslide to 4, which will make things easier because now you don't need to edit the back and next buttons.

Try that out and see how it goes. Smile
WebHead




PostPosted: Fri May 27, 2005 9:01 pm   Post subject: for buttons help

i need to clear the screen of the old calculations when i click a new button. So when i click a button, i do what it says, then when i go to click another of the buttons, the put statements come up but the old calculations are still there and get over written. all i need is something to clear the old calculations but still have the 3 buttons on the screen. Thanx, have fun with it Smile


import GUI

setscreen("graphics:600;250")






%*********************************************Calculate Circle****************************************************






%procedures containing all the work you want that button to do
procedure circle
locate (1,1)
colour (01)


const Pi:=3.1415922653 %formula for pie
var Radius:real %variable to find radius

put "Area of a Circle" %title statement
put "Type in your radius: " .. %intructional statement

get Radius %User's Radius

colour (12)

put "The area of the circle with the given radius is: " ,Pi*Radius**2:1:3 ," sq.cm."
%last statemenmt and formula to calculate
end circle






%*********************************************Calculate Rectangle****************************************************






procedure rectangle
locate(1,1)
colour (01)



var Length:int
var Width:int

put "The Area of a Rectangle"
put "Type in your length and width of rectangle (eg L W): " .. %statement to get length and width

colour (12)

get Length
get Width %get user's information

put "The area of your rectangle is: " ,(Length*2)+(Width*2):1:3 ," sq.cm."
end rectangle






%*********************************************Calculate Triangle****************************************************





procedure triangle
locate(1,1)
colour (01)


var Base:int
var Height:int %both needed to calculate the area of a trainge

put "The Area of a Triangle" %title statement
put "Type your base and height (eg 4 2): " .. %statement explaing to user what to typt

get Base
get Height %get commands the get information from user

colour (12)

put "The area of your triangle is: " ,0.5*Base*Height:1:3 ," sq cm."
end triangle

%button names as variables %create buttons
var button1:int:=GUI.CreateButton(25,25,0,"Calculate Area of Circle",circle)
var button2:int:=GUI.CreateButton(25,50,0,"Calculate Area of Rectangle",rectangle)%names of buttons
var button3:int:=GUI.CreateButton(25,75,0,"Calcualte Area of Triangle",triangle)

%*********************************************Main Loop****************************************************



loop
exit when GUI.ProcessEvent
end loop
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: