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

Username:   Password: 
 RegisterRegister   
 Help with menu-oriented mousewhere program (exits and ending)?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
helen.happy




PostPosted: Tue May 11, 2010 5:41 pm   Post subject: Help with menu-oriented mousewhere program (exits and ending)?

What is it you are trying to achieve?
I'm doing a database program with menus, and I can't seem to figure out the logical fail that is causing the mousewhere processes to be faulty.

What is the problem you are having?
In this program there is a main menu, a submenu, and then a screen that displays the information from a file. From there I have a "click anywhere to exit" on the screen, but it doesn't work. Instead, it goes to the next "if", switching to the Female listings, and vice versa.

Describe what you have tried to solve this problem
I've tried declaring procedures outside, looping in multiple places, adding a button:=0, rearranging the program...

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

This is the problem area, to my knowledge.

Turing:


% end screen
procedure ending
    var endscreen : int := Pic.FileNew ("snoopyend.gif")
    Pic.Draw (endscreen, 0, 0, 0)
end ending

procedure gendermenu
   var genderpic : int := Pic.FileNew ("snoopygender.gif")
   var male : int := Pic.FileNew ("snoopymale.gif")
   var female : int := Pic.FileNew ("snoopyfemale.gif")
   var font1 : int := Font.New ("Verdana:10")
   Pic.Draw (genderpic, 0, 0, 0)
    loop
    mousewhere (x, y, button)
    % IF THEY CLICK MALE
    if button = 1 and x > 254 and x < 500 and y > 300 and y < 355 then
        button:=0
        cls
        Pic.Draw (male, 0, 0, 0)
        var down, down2, down3, down4, down5, down6 : int := 400
        for i : 1 .. 27
            if gender (i) = "Male" then
                Font.Draw (name (i), 4, down, font1, 7) % putting the names of them
                down := down - 13
                % end putting their names
                Font.Draw (gender (i), 130, down2, font1, 7) % putting their gender
                down2 := down2 - 13
                % end putting gender
                Font.Draw (species (i), 190, down3, font1, 7) % putting their species
                down3 := down3 - 13
                % end putting their species
                Font.Draw (talent (i), 250, down4, font1, 7) % putting their talent
                down4 := down4 - 13
                % end putting their talents
                Font.Draw (hair (i), 340, down5, font1, 7) % putting their hair
                down5 := down5 - 13
                % end putting their talents
                Font.Draw (habitat (i), 400, down6, font1, 7) % putting their hair
                down6 := down6 - 13
                end if
        end for
        exit when button=1

    % IF THEY CLICK FEMALES
    elsif button = 1 and x > 254 and x < 500 and y > 240 and y < 300 then
        button:=0
        cls
        Pic.Draw (female, 0, 0, 0)
        var down, down2, down3, down4, down5, down6 : int := 370
        for i : 1 .. 27
            if gender (i) = "Female" then
                Font.Draw (name (i), 4, down, font1, 7) % putting the names of them
                down := down - 13
                % end putting their names
                Font.Draw (gender (i), 130, down2, font1, 7) % putting their gender
                down2 := down2 - 13
                % end putting gender
                Font.Draw (species (i), 190, down3, font1, 7) % putting their species
                down3 := down3 - 13
                % end putting their species
                Font.Draw (talent (i), 250, down4, font1, 7) % putting their talent
                down4 := down4 - 13
                % end putting their talents
                Font.Draw (hair (i), 340, down5, font1, 7) % putting their hair
                down5 := down5 - 13
                % end putting their talents
                Font.Draw (habitat (i), 400, down6, font1, 7) % putting their hair
                down6 := down6 - 13

            end if
        end for
        exit when button=1

            end if
       end loop
end gendermenu

% THE MAIN MENU SCREEN
var mainmenu : int := Pic.FileNew ("snoopymenu.gif")
loop
Pic.Draw (mainmenu, 0, 0, 0)
mousewhere (x, y, button)
if button = 1 and x > 365 and x < 499 and y > 432 and y < 450 then
ending
elsif button = 1 and x > 312 and x < 470 and y > 173 and y < 215 then
gendermenu
elsif button = 1 and x > 312 and x < 470 and y > 136 and y < 173 then
speciesmenu
elsif button = 1 and x > 312 and x < 470 and y > 99 and y < 136 then
talentsmenu
elsif button = 1 and x > 312 and x < 470 and y > 63 and y < 99 then
hairmenu
elsif button = 1 and x > 312 and x < 470 and y > 27 and y < 63 then
habitatmenu
end if
exit when button = 1 and x > 365 and x < 499 and y > 432 and y < 450
end loop



Please specify what version of Turing you are using
4.1.1

Any help would be very much appreciated, since I'm pretty desperate at this point; I thought I had it all figured out, until this step! ^^;
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue May 11, 2010 5:51 pm   Post subject: RE:Help with menu-oriented mousewhere program (exits and ending)?

In debugging how your code flows, it helps to know the exact values held by your variables. If you expect the code to go into an if statement, but it doesn't, then at least one of the values is not what you are expecting it to be -- add some debug statements, such as
code:

put "button: ", button, " x: ", x, " y: ", y
if button = 1 and x > 254 and x < 500 and y > 300 and y < 355 then
...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
USEC_OFFICER




PostPosted: Tue May 11, 2010 7:13 pm   Post subject: RE:Help with menu-oriented mousewhere program (exits and ending)?

Ahem, exit when button = 1? And then there is no mouse.where in afterwards?
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  [ 3 Posts ]
Jump to:   


Style:  
Search: