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

Username:   Password: 
 RegisterRegister   
 GUI help (with the 'include' statement)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mario64mario




PostPosted: Sat Oct 25, 2008 8:22 am   Post subject: GUI help (with the 'include' statement)

Okay, so I've got three buttons made, and when each one is clicked, I want them to include other files, but whilst getting rid of the original three buttons. I used 'cls', but the buttons stay. Is there any other way to get rid of them other than GUI.Hide?

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main window
code:
%This program mimics an online store. It allows users to browse items on sale
%and allows users to purchase items. It also has a 'Company Info' page.


%<-------------------------------------Menu Screen------------------------------------->

import GUI

%Declarations
var menu, button1, button2, button3 : int

%Music
Music.PlayFileReturn ("sonic.mp3")

%Menu Display
locate (7, 1)
put "The Legend of Gaming"
put "Please select an option from the menu"
put skip
put "---MENU---"

%Button Procedures
procedure Button1Pressed
    Music.PlayFileStop
    cls
    include "browse.t"
end Button1Pressed
procedure Button2Pressed
    Music.PlayFileStop
    cls
    include "purchase.t"
end Button2Pressed
procedure Button3Pressed
    Music.PlayFileStop
    cls
    include "company.t"
end Button3Pressed

%Button Creations
loop
    View.Set ("offscreenonly")
    button1 := GUI.CreateButton (250, maxy - 200, 100, "Browse Our Items",
        Button1Pressed)
    GUI.SetColor (button1, brightred)
    button2 := GUI.CreateButton (400, maxy - 200, 100, "Complete Your Purchase",
        Button2Pressed)
    GUI.SetColor (button2, green)
    button3 := GUI.CreateButton (345, maxy - 250, 100, "About Us",
        Button3Pressed)
    GUI.SetColor (button3, brightblue)
    View.Update
    exit when GUI.ProcessEvent
end loop


"Browse Our Items" (example of the 'include' statement)

code:
%This program allows users to browse items on sale.

put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."
put "This is where you will look at items and see if you want them."


Turing displays the wall of text behind the three buttons. Can anyone help?

Side Note: Sorry if the GUI construct is a bit messy. I learned it about 2 hours ago.
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Sat Oct 25, 2008 9:25 am   Post subject: Re: GUI help (with the 'include' statement)

GUI.Dispose will totally get rid of the buttons, but I don't think that this is what you want.
I'm assuming you want GUI.Hide so that way the user can return to the menu and see those buttons again.
The reason GUI.Hide isn't working for you is because you are recreating the buttons every time inside the loop,
using exit when GUI.ProcessEvent will redraw every button that is not being hid at that time, so declare your buttons outside the loop.
Then when you include something use GUI.Hide for the 3 buttons and they will out of sight.

Turing:


procedure Hide
    GUI.Hide (button1)
    GUI.Hide (button2)
    GUI.Hide (button3)
    GUI.Show (button4)
    %by calling this Hide proc it will hide all the menu buttons and show the return button
end Hide
proc returnToMenu
    cls
    GUI.Show (button1)
    GUI.Show (button2)
    GUI.Show (button3)
    GUI.Hide (button4)
    %this will show all the menu items again, and remove the return button
end returnToMenu

button1 := GUI.CreateButton (250, maxy - 200, 100, "Browse Our Items", Button1Pressed)
GUI.SetColor (button1, brightred)
button2 := GUI.CreateButton (400, maxy - 200, 100, "Complete Your Purchase", Button2Pressed)
GUI.SetColor (button2, green)
button3 := GUI.CreateButton (345, maxy - 250, 100, "About Us", Button3Pressed)
GUI.SetColor (button3, brightblue)
button4 := GUI.CreateButton (500, 20, 100, "Return", returnToMenu)
GUI.SetColor (button3, red)
GUI.Hide (button4)
loop
    exit when GUI.ProcessEvent
    exit when hasch
end loop
mario64mario




PostPosted: Sat Oct 25, 2008 10:15 am   Post subject: Re: GUI help (with the 'include' statement)

okay, I've put this in the 'browse.t' file

code:
button4 := GUI.CreateButton (250, maxy - 200, 100, "Browse Our Items", ReturnToMenu)
GUI.SetColor (button4, brightgreen)


and I've declared the 'ReturnToMenu' procedure in the main program

code:
procedure ReturnToMenu
    cls
    GUI.Show (button1)
    GUI.Show (button2)
    GUI.Show (button3)
end ReturnToMenu

I go and run it, and it opens the 'browse.t' and says that the procedure called 'ReturnToMenu' has not been declared. Any help?
The_Bean




PostPosted: Sat Oct 25, 2008 10:55 am   Post subject: Re: GUI help (with the 'include' statement)

Declare it with the others and hide it at the start then when you enter the browsing option use GUI.Show on it.
mario64mario




PostPosted: Sat Oct 25, 2008 11:34 am   Post subject: Re: GUI help (with the 'include' statement)

I did that. It doesn't show 'browse' or call upon 'button4' or 'ReturnToMenu' until the 'browse' button is clicked.

Here's the updated program:
Turing:

%This program mimics an online store. It allows users to browse items on sale
%and allows users to purchase items. It also has a 'Company Info' page.


%<-------------------------------------Menu Screen------------------------------------->

import GUI

%Declarations
var menu, button1, button2, button3, button4 : int

%Music
Music.PlayFileReturn ("sonic.mp3")

%Menu Display
locate (7, 1)
put "The Legend of Gaming"
put "Please select an option from the menu"
put skip
put "---MENU---"

%Button Procedures
procedure Button1Pressed
    Music.PlayFileStop
    cls
    GUI.Hide (button1)
    GUI.Hide (button2)
    GUI.Hide (button3)
    include "browse.t"
end Button1Pressed
procedure Button2Pressed
    Music.PlayFileStop
    cls
    GUI.Hide (button1)
    GUI.Hide (button2)
    GUI.Hide (button3)
    include "purchase.t"
end Button2Pressed
procedure Button3Pressed
    Music.PlayFileStop
    cls
    GUI.Hide (button1)
    GUI.Hide (button2)
    GUI.Hide (button3)
    include "company.t"
end Button3Pressed
procedure ReturnToMenu
    cls
    GUI.Show (button1)
    GUI.Show (button2)
    GUI.Show (button3)
    GUI.Hide (button4)
end ReturnToMenu

%Button Creations
View.Set ("offscreenonly")
button1 := GUI.CreateButton (250, maxy - 200, 100, "Browse Our Items",
    Button1Pressed)
GUI.SetColor (button1, brightred)
button2 := GUI.CreateButton (400, maxy - 200, 100, "Complete Your Purchase",
    Button2Pressed)
GUI.SetColor (button2, green)
button3 := GUI.CreateButton (345, maxy - 250, 100, "About Us",
    Button3Pressed)
GUI.SetColor (button3, brightblue)
View.Update
loop
    exit when GUI.ProcessEvent
    exit when hasch
end loop


and the updated 'browse.t':

Turing:

%October 27th, 2008
%This program allows users to browse items on sale.

put "This is where you will look at items and see if you want them."


button4 := GUI.CreateButton (250, maxy - 200, 100,
"Return to Main Menu", ReturnToMenu)
GUI.SetColor (button4, brightgreen)
The_Bean




PostPosted: Sat Oct 25, 2008 2:03 pm   Post subject: Re: GUI help (with the 'include' statement)

Your problem is with View.Update.
The GUI doesn't have View.Update built in with it, so when you click on it, the screen doesn't get updated with the animation, and your not updating the screen when you go to the include.
Turing:

import GUI
var button1, button2, button3, button4 : int
Music.PlayFileReturn ("sonic.mp3")

proc returnToMenu
    cls
    GUI.Show (button1)
    GUI.Show (button2)
    GUI.Show (button3)
    GUI.Hide (button4)
end returnToMenu
proc Hide
    cls
    GUI.Hide (button1)
    GUI.Hide (button2)
    GUI.Hide (button3)
    GUI.Show (button4)
end Hide

proc menu
    returnToMenu
    locate (7, 1)
    put "The Legend of Gaming"
    put "Please select an option from the menu"
    put skip
    put "---MENU---"
end menu
procedure Button1Pressed
    Music.PlayFileStop
    cls
    Hide
    include "browse.t"
end Button1Pressed
procedure Button2Pressed
    Music.PlayFileStop
    cls
    Hide
    include "purchase.t"
end Button2Pressed
procedure Button3Pressed
    Music.PlayFileStop
    cls
    Hide
    include "company.t"
end Button3Pressed
button1 := GUI.CreateButton (250, maxy - 200, 100, "Browse Our Items", Button1Pressed)
GUI.SetColor (button1, brightred)
button2 := GUI.CreateButton (400, maxy - 200, 100, "Complete Your Purchase", Button2Pressed)
GUI.SetColor (button2, green)
button3 := GUI.CreateButton (345, maxy - 250, 100, "About Us", Button3Pressed)
GUI.SetColor (button3, brightblue)
button3 := GUI.CreateButton (345, maxy - 250, 100, "About Us", Button3Pressed)
GUI.SetColor (button3, brightblue)
button4 := GUI.CreateButton (500, 20, 100, "Return", menu)
GUI.SetColor (button4, red)
GUI.Hide (button4)

menu
loop
    exit when GUI.ProcessEvent
    exit when hasch
end loop
mario64mario




PostPosted: Sat Oct 25, 2008 2:10 pm   Post subject: Re: GUI help (with the 'include' statement)

I ran it, and still got the same message >.>

" 'ReturnToMenu' has not been declared "
The_Bean




PostPosted: Sat Oct 25, 2008 2:13 pm   Post subject: Re: GUI help (with the 'include' statement)

returnToMenu is the first thing declared other than the variables, so that doesn't make sense.
Did you copy and paste it into a new turing window?
Sponsor
Sponsor
Sponsor
sponsor
mario64mario




PostPosted: Sat Oct 25, 2008 2:22 pm   Post subject: Re: GUI help (with the 'include' statement)

okay, I got the thing to link proerly by taking out 'ReturnToMain' in it's entirety. Here's the new line of code:

Turing:

proc menu
    cls
    GUI.Show (button1)
    GUI.Show (button2)
    GUI.Show (button3)
    GUI.Hide (button4)
    locate (7, 1)
    put "The Legend of Gaming"
    put "Please select an option from the menu"
    put skip
    put "---MENU---"
end menu

It links propery, but when I go back to the main menu, it doesn't show the button for the area I just came from. If I click the area the button should be, then it goes there. Confused


EDITED:
okay, I think the environment is just a bit glitchy. Thanks for the help, The_Bean ^_^
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  [ 9 Posts ]
Jump to:   


Style:  
Search: