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

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




PostPosted: Tue Dec 10, 2013 7:04 pm   Post subject: GUI with loops?

What is it you are trying to achieve?
Get my GUI buttons to work alongside loops


What is the problem you are having?
The GUI buttons do not work when loops are running beside them


Describe what you have tried to solve this problem
I have tried many things, just no success


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

Turing:

import GUI

procedure Start
%Process code
end Start
procedure Exit
%Process code
end Exit
procedure Instructions
%Process code
end Instructions


%My buttons assigned to variables and procedures.
var StartButton : int := GUI.CreateButton (400, 203, 93, "Start", Start)
var InstructionButton : int := GUI.CreateButton (400, 180, 0, "Instructions", Instructions)
var ExitButton : int := GUI.CreateButton (400, 157, 93, "Exit", Exit)

%Intro Continued (Had to put this part after the buttons were drawn)
loop
    %The Hangman
    drawfilloval (100, 320, 20, 20, red) %head
    drawfilloval (100,310,10,4,white) %mouth
    drawfilloval (93, 323, 5, 5, white) %left eye
    drawfilloval (107, 323, 5, 5, white) %right eye
    drawfilloval (93, 323, 2, 2, black) %left pupil
    drawfilloval (107, 323, 2, 2, black) %right pupil
    drawline (100, 220, 100, 300, red) %body
    drawline (100, 220, 130, 180, red) %right leg
    drawline (100, 220, 70, 180, red) %left leg
    drawline (100, 260, 140, 260, red) %right arm
    drawline (100, 260, 60, 260, red) %left arm
    %Moving Arms
    for x : 0 .. 40
        drawline (100, 260, 60, 260 + x, red) %left arm
        drawline (100, 260, 140, 260 + x, red) %right arm
        delay (25)
        drawline (100, 260, 60, 260 + x, 11) %left arm
        drawline (100, 260, 140, 260 + x, 11) %right arm
    end for
    %Moving Arms 2
    for x : 0 .. 40
        drawline (100, 260, 60, 300 - x, red) %left arm
        drawline (100, 260, 140, 300 - x, red) %right arm
        delay (25)
        drawline (100, 260, 60, 300 - x, 11) %left arm
        drawline (100, 260, 140, 300 - x, 11) %right arm
    end for
end loop

loop
    exit when GUI.ProcessEvent
end loop


Any help would be greatly appreciated! What this basically is, is a graphic of a stick man waving. This is looped so he does it forever until you want to play the game (Hangman opening menu)

The problem I am having is obviously that GUI buttons do not work when loops are running in the same process. I was just wondering a way around this? I would love to keep both aspects of my menu without having to remove anything.

Thanks!
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Tue Dec 10, 2013 8:30 pm   Post subject: RE:GUI with loops?

Your first loop runs forever, so the second loop with GUI.ProcessEvent never executes. Why not put GUI.ProcessEvent in the same loop as everything else?
Mooonty




PostPosted: Wed Dec 11, 2013 8:10 am   Post subject: RE:GUI with loops?

Even when putting GUI.ProcessEvent in the same loop, the buttons are still not clickable.
Insectoid




PostPosted: Wed Dec 11, 2013 3:07 pm   Post subject: RE:GUI with loops?

Actually, the buttons are clickable. The problem is that your program spends so much time going through your for loops that Turing has trouble detecting your clicks. If you comment out the for loops it works just fine (after moving GUI.ProcessEvent into the main loop of course). I'm not sure if there's a 'correct' way to solve this, however you can fix it by creating your own buttons (with Draw.Box and Mouse.Where), which is a little bit complicated, or by moving your for loops into a separate process and forking it, which is also pretty complicated and can cause all sorts of weird bugs.
Tony




PostPosted: Wed Dec 11, 2013 4:14 pm   Post subject: Re: RE:GUI with loops?

Insectoid @ Wed Dec 11, 2013 3:07 pm wrote:
I'm not sure if there's a 'correct' way to solve this

You are spot on with your analysis that internal for-loops take way to much time. The correct way is to replace internal for-loops by using a frame counter in a single main loop, and draw one frame at a time.
code:

loop
   frame += 1
   draw_frame(frame)
   GUI.ProcessEvent
   delaySinceLast
end loop
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: Wed Dec 11, 2013 4:27 pm   Post subject: RE:GUI with loops?

Quote:
The correct way is to replace internal for-loops by using a frame counter in a single main loop, and draw one frame at a time.


Oh, right. I just assumed the for loops were drawing 40 things, rather than drawing an animation. Silly me for not thinking of that.
Mooonty




PostPosted: Wed Dec 11, 2013 5:16 pm   Post subject: RE:GUI with loops?

Thanks everyone for the feedback, I found a way around it by just limiting the loop to run for a small time period so that the buttons are clickable after the loop has finished. I might consider looking into these cool little tricks as well. Thanks!
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: