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

Username:   Password: 
 RegisterRegister   
 GUI running with loop
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Abdiwahab




PostPosted: Mon Jan 14, 2008 8:00 pm   Post subject: GUI running with loop

I have a computer game ISP due Wednesday. So far, I got everything down fine, but I'm stuck now. My teacher said that we had to include a button in the game screens that goes back to main menu if the user wants to opt out of playing and return to the start screen. But what sucks is my GUI doesn't work cuz I have a loop running in the same procedure. Can anyone help me?

Turing:

procedure l1
    title
    level := 1
    qolor (1) := 150
    qolor (2) := 50
    qolor (3) := 50
    qolor (4) := 150
    next := 0
    counter := 0
    drawfillbox (50, 320, 100, 370, grey)
    drawfillbox (150, 320, 200, 370, grey)
    drawfillbox (250, 320, 300, 370, grey)
    drawfillbox (350, 320, 400, 370, grey)
    drawfillbox (540, 320, 640, 370, red)
    Draw.Text ("GUESS", 560, 340, lhfont, white)
    GUI.Show (menuButton)
    GUI.Enable (menuButton)
    loop
        mousewhere (x, y, button)
        if button = 1 and x > 540 and x < 640 and y > 320 and y < 370 then
            counter := counter + 1
            next := next + 55
            checker
            locate (24, 1)
            if number = 4 then
                put "You got it!"
                pauseProgram
                exit
            else
                put number, " pegs are in the right place.         You have ", 5 - counter, " more tries left!"
            end if
            if counter = 5 and number not= 4 then
                locate (24, 1)
                put "Nope. Let's hope you do better in the next level."
                pauseProgram
                exit
            end if
            pauseProgram
            drawfillbox (0, 0, 540, 34, white)
            number := 0
        end if
        if button = 1 and y > 35 + next and y < 85 + next then
            if x > 50 and x < 100 then
                which := 1
                change
            elsif x > 150 and x < 200 then
                which := 2
                change
            elsif x > 250 and x < 300 then
                which := 3
                change
            elsif x > 350 and x < 400 then
                which := 4
                change
            end if
        end if
        drawfillbox (50, 35 + next, 100, 85 + next, kolor (1))
        drawfillbox (150, 35 + next, 200, 85 + next, kolor (2))
        drawfillbox (250, 35 + next, 300, 85 + next, kolor (3))
        drawfillbox (350, 35 + next, 400, 85 + next, kolor (4))
        delay (100)
    end loop
    next := 0
    counter := 0
    number := 0
    for z : 1 .. 8
        kolor (z) := 50
    end for
    l2
end l1



^That doesn't work. Is there anyway to make a button and a loop run at the same time without the button just uselessly sitting there?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jan 14, 2008 8:24 pm   Post subject: RE:GUI running with loop

You need to place GUI.ProcessEvents inside the loop, so that it can process any events that might happen to GUI (such as mouse clicks, etc).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Abdiwahab




PostPosted: Mon Jan 14, 2008 9:06 pm   Post subject: Re: GUI running with loop

Thanks Tony! I added this:

Turing:

    GUI.Show (menuButton)
    GUI.Enable (menuButton)
    loop
        exit when GUI.ProcessEvent
    end loop

...but this loop gets in the way of the other loop and makes it so that the other loop isn't displayed. Sad
How can u make it so that the two loops run at the same time?
Tony




PostPosted: Mon Jan 14, 2008 9:35 pm   Post subject: RE:GUI running with loop

why not just combine the contents of the loops together?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Abdiwahab




PostPosted: Mon Jan 14, 2008 9:49 pm   Post subject: RE:GUI running with loop

Anywhere I put it, its still waiting for the GUI to be clicked before doing anything else.
Tony




PostPosted: Mon Jan 14, 2008 9:55 pm   Post subject: RE:GUI running with loop

that would largely depend on your logic flow. Try to step through your program, one line at a time, and see how loops and if-conditions affect the flow. If you get stuck anywhere (for example, loop doesn't exit, or the program is waiting for user input), then that's the problem.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Abdiwahab




PostPosted: Mon Jan 14, 2008 10:00 pm   Post subject: RE:GUI running with loop

LOL just as I sent the last reply I noticed that if-statements work even better then exit when which is what u said right now:

Turing:

loop
     .........
     if GUI.ProcessEvent then
          exit
     end if
end loop


Thanks for all your help Very Happy
Compsci is awesome Very Happy
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  [ 7 Posts ]
Jump to:   


Style:  
Search: