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

Username:   Password: 
 RegisterRegister   
 Need help in turing. Changing screens.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
feebas200




PostPosted: Thu Mar 31, 2011 3:40 pm   Post subject: Need help in turing. Changing screens.

Hi there, I'm new to this forum.

What I want to do is make is so I can change screens back and fourth like rooms. I know how to make the buttons for it but I don't know the command for it top go back to the first part of the program. I can make the continue and move forward to the next room but it can't return to previous rooms after. I hope someone helps, Thanks in advance. Surprised

Version of turing 4.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Mar 31, 2011 3:46 pm   Post subject: RE:Need help in turing. Changing screens.

You're being very vague here. We need more information.
feebas200




PostPosted: Thu Mar 31, 2011 4:04 pm   Post subject: Re: Need help in turing. Changing screens.

like a button that switches between two screens. A button that makes you go to a living room and another button going to like kitchen something like that. So when you press the button you go to the living room and when you press another button you return to kitchen. And the button works forever.

Making it so when you press the button the current room clears and you end up in another room.

Like entering a menu screen, you press a button to go to intructions, but you can return to menu screen.
Tony




PostPosted: Thu Mar 31, 2011 4:19 pm   Post subject: RE:Need help in turing. Changing screens.

loops.
code:

loop
   % what room was I in again?
   % oh right, it was the kitchen
   % draw kitchen
   % do stuff
end loop % repeat
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
feebas200




PostPosted: Thu Mar 31, 2011 5:08 pm   Post subject: Re: Need help in turing. Changing screens.

code:

import GUI
%Sets the mode to graphics mode and changes the resolution
%It also positions it on the center of the screen with nobutton bar
setscreen ("graphics:700;420,position:center;center,nobuttonbar")


%
drawfillbox (0, 0, maxx, maxy, 186)
drawfillbox (190, 0, 530, 790, 68)
var back3 : int := Pic.New (0, 0, maxx, maxy)



var num : int := 1
const transname : array 1 .. 1 of string := init ("picFadeIn")
const  trans : array 1 .. 1 of int := init (picFadeIn)
var transitions := upper (transname)

var font1 : int
font1 := Font.New ("serif:12:bold")
var x1, y1, b1 : int



drawfillbox (0, 0, 100, 50, black)
Font.Draw ("Enter House", 6, 20, font1, white)
loop
    Mouse.Where (x1, y1, b1)
    if b1 = 1 %mouse down
            then

        if y1 < 50 and x1 < 100 then
            %basically you clicked inside the rectangle object

            exit

        else

        end if
    end if
end loop

Pic.DrawSpecial (back3, 0, 0, picCopy, trans (num), 2500)

delay (1500)
cls






%Room
%Refreshes the GUI
GUI.Refresh

%Sets the screen resolution in graphics mode and removes the buttonbar.
%It is positioned at the center of the screen
setscreen ("graphics:1150;690,position:center;center,nobuttonbar")
% Determine the number of frames in the gif
% Create the original picture
var numFrames := Pic.Frames ("Mario.gif")
% Loads the picture
var delayTime : int
var pic : array 1 .. numFrames of int
var TV : boolean := false

Pic.FileNewFrames ("Mario.gif", pic, delayTime)

%The procedure of the buttons is set
%Boolean is used
procedure button
    TV := true
    GUI.Refresh
end button

procedure button1
    TV := false
    GUI.Refresh
end button1



proc room
    %Fills in the colour of the wall to green
    drawfill (2, 180, 97, 97)

    %Draws the edges of the room
    drawline (1200, 0, 910, 180, black)
   
    drawline (910, 180, 910, 900, black)
   
    drawline (0, 180, 910, 180, black)

    %Fills the floor with the colour grey with black borders
    drawfill (100, 5, 30, black)

    drawfillbox (0, 0, 200, 50, black)
    Font.Draw ("Go to left side of the room", 6, 20, font1, white)
    loop
        Mouse.Where (x1, y1, b1)
        if b1 = 1 %mouse down
                then

            if y1 < 50 and x1 < 200 then
                %basically you clicked inside the rectangle object
                cls
                exit
            else

            end if
        end if
    end loop
    %Fills in the colour of the wall to green
    drawfill (2, 180, 97, 97)

    %Draws the edges of the room
    drawline (0, 0, 180, 180, black)
    drawline (180, 180, 180, 900, black)
    drawline (180, 180, 1500, 180, black)

    %Fills the floor with the colour grey with black borders
    drawfill (100, 5, 30, black)

    %Draws a black television
    drawfillbox (465, 225, 855, 552, black)
    %Draws the screen for the television
    drawfillbox (499, 255, 821, 531, 20)


    %Draws the shelf holding the gaming system
    drawfillbox (465, 215, 855, 150, black)

    %Draws a column that holds up the shelf
    drawfillbox (465, 230, 480, 150, black)
    %Draws a column that holds up the shelf
    drawfillbox (820, 230, 855, 150, black)

    %Draws the gaming system
    drawfillbox (580, 165, 730, 210, white)

    %Draws the power button
    drawfilloval (600, 185, 12, 12, grey)

    %Draws the CD Rom on the gaming system
    drawfillbox (625, 185, 695, 190, grey)

    %Draws a line that seperates parts of the machine
    drawfillbox (702, 165, 702, 210, black)

    %Draws button/slot
    drawfilloval (720, 175, 4, 4, black)
    %Draws button/slot
    drawfilloval (720, 195, 4, 4, black)

    %Draws a line to make the shelf look 3-Dimensional
    drawline (837, 150, 820, 215, white)
    %Draws a line to make the shelf look 3-Dimensional
    drawline (480, 150, 484, 215, white)
    %Draws the back part of the gaming system
    drawfillbox (580, 210, 728, 218, white)
    %
    %Draws the fish tank and water inside
    drawfillbox (200, 450, 430, 460, black)
    drawfillbox (200, 300, 198, 460, black)
    %Draws the water in the tank
    drawfillbox (200, 300, 430, 450, 101)
    drawfillbox (431, 300, 433, 460, black)
    drawfillbox (198, 300, 433, 290, black)

    %declares the pic ID for storing the image
    var picid : int
    %Imports the controller into the program
    picid := Pic.FileNew ("controller.bmp")
    %Draws the controller and merges it in the background
    Pic.Draw (picid, 550, -17, picMerge)
    %Imports the gold fish into the program
    var picid1 : int
    picid1 := Pic.FileNew ("fish2.jpg")

    %Draws a fish swimming across the fish tank
    for k : 1 .. 130
        Pic.Draw (picid1, 340 - k, 305, picMerge)
        %Fish moves every 30 milliseconds
        delay (30)
    end for



    %On and off buttons are created
    var c : int := GUI.CreateButton (645, 228, 0, "On", button)
    var quitBtn1 : int := GUI.CreateButton (695, 228, 0, "Off", button1)

    drawfillbox (0, 0, 150, 50, black)
    Font.Draw ("Return to first room", 6, 20, font1, white)
   


    %Refresh the GUI
    GUI.Refresh
    %Starts a loop
 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




  loop
        Mouse.Where (x1, y1, b1)
        if b1 = 1 %mouse down
                then

            if y1 < 50 and x1 < 150 then
                %basically you clicked inside the rectangle object
 


%I want it to return to top part
              return
 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

         else

                %Checks if TV is true
                if TV = true then
                    %Starts playing mario music (Looped)
                    Music.PlayFileLoop ("mario.mp3")
                    %Draws the frames of the picture (GIF)
                    Pic.DrawFrames (pic, 500, 250, picMerge, numFrames, 50, false)
                    %Checks if  TV is false
                elsif TV = false then
                    %Stops the music
                    Music.PlayFileStop
                    %Draws a grey box that covers the screen
                    drawfillbox (499, 250, 821, 531, 20)
                end if
                exit when GUI.ProcessEvent
                end if
end if
                end loop
            %Loop ends

 
            end room

            proc show
    %Fills in the colour of the wall to green
    drawfill (2, 180, 97, 97)

    %Draws the edges of the room
    drawline (1200, 0, 910, 180, black)
   
    drawline (910, 180, 910, 900, black)
   
    drawline (0, 180, 910, 180, black)

    %Fills the floor with the colour grey with black borders
    drawfill (100, 5, 30, black)

    drawfillbox (0, 0, 200, 50, black)
    Font.Draw ("Go to left side of the room", 6, 20, font1, white)
    loop
        Mouse.Where (x1, y1, b1)
        if b1 = 1 %mouse down
                then

            if y1 < 50 and x1 < 200 then
                %basically you clicked inside the rectangle object
                cls
                room
            else

            end if
        end if
    end loop

end show
       
room


That's not what I mean. You see the first part of my program? It basically exits so it goes to another room, however, I can't make a button to return to the first room. The % surrounded part of the program is where i`m trying to make it get back to top. But once I exit I can`t get back to the first room.
Raknarg




PostPosted: Thu Mar 31, 2011 6:58 pm   Post subject: RE:Need help in turing. Changing screens.

Just out of curiosity, is there any real benifit to using GUI buttons as opposed to Mouse.Where buttons? If not, I would suggest those, they seem to be simpler than GUIs.
feebas200




PostPosted: Thu Mar 31, 2011 7:04 pm   Post subject: RE:Need help in turing. Changing screens.

Oh, I found out how to do the mousewhere buttons recently, this is a school project so I don't want to redo the GUI buttons so I left it there.
Any suggestions for changing screens back and forth?
Tony




PostPosted: Thu Mar 31, 2011 8:14 pm   Post subject: RE:Need help in turing. Changing screens.

I'm telling you -- loops. This tutorials is particularly relevant -- http://compsci.ca/v3/viewtopic.php?t=370
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
feebas200




PostPosted: Thu Mar 31, 2011 8:36 pm   Post subject: Re: Need help in turing. Changing screens.

EDIT~~~~ I Managed to get back to first room but it is automatic and not manual. I don't get why it's going to the other room automatically. I tried using exitwhen but the screen stays white because i needed to use cls. If i try to make it exit when I click the mouse at a certain location then it just reloops the room, it only works when I use only exit right after endloop

code:

%Starts a loop
        loop
            Mouse.Where (x1, y1, b1)
            if b1 = 1 %mouse down
                    then

                if y1 < 50 and x1 < 150 then
                    %basically you clicked inside the rectangle object

                    exit when b1 = 1
                else

                    %Checks if TV is true
                    if TV = true then
                        %Starts playing mario music (Looped)
                        Music.PlayFileLoop ("mario.mp3")
                        %Draws the frames of the picture (GIF)
                        Pic.DrawFrames (pic, 500, 250, picMerge, numFrames, 50, false)
                        %Checks if  TV is false
                    elsif TV = false then
                        %Stops the music
                        Music.PlayFileStop
                        %Draws a grey box that covers the screen
                        drawfillbox (499, 250, 821, 531, 20)
                    end if
                    exit when GUI.ProcessEvent
                end if
            end if
 

%ADDING THIS allowed me to go to previous room but it is automatic
%I tried exit when b1=1 but it ended up repeating the same room.
           exit
 


      end loop
        %Loop ends
        cls
    end loop
feebas200




PostPosted: Sun Apr 03, 2011 6:31 pm   Post subject: RE:Need help in turing. Changing screens.

i still need help. :[. My assignment will be due soon.
Tony




PostPosted: Sun Apr 03, 2011 6:46 pm   Post subject: RE:Need help in turing. Changing screens.

If you have just an "exit", then it will always ("automatically") exit from the loop.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
feebas200




PostPosted: Sun Apr 03, 2011 8:00 pm   Post subject: RE:Need help in turing. Changing screens.

But when I try to use "exit when b1=1" it doesn't go back to start anymore. Trick doesn't work. Any suggestions?
Tony




PostPosted: Sun Apr 03, 2011 8:04 pm   Post subject: RE:Need help in turing. Changing screens.

so presumably b1 is either never 1 at that point, or it is, and so the code does something other than you're expecting. Time to investigate further.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
feebas200




PostPosted: Mon Apr 04, 2011 8:03 pm   Post subject: RE:Need help in turing. Changing screens.

~~~~~~~RESOLVED~~~~~~~~~~~~~~~~~~well now the room changes when i click anywhere on the screen, how do I make it at a certain area? My button just replays the room right now but if i click anywhere else then the button then it will change rooms.

I tried "exit when y1 < 50 and x1 < 150 and b1 =1" but the button just replays the current screen now.#~~~~~~~~~~~~~~~~~~~~~~
Tony




PostPosted: Mon Apr 04, 2011 8:40 pm   Post subject: RE:Need help in turing. Changing screens.

I'll make a wild guess that when that loop exits, you are still holding the mouse down in that in that area (and/or the variables still hold such values).

Use put statements to confirm that all the variables hold the values that you expect them to, and that code is executing in places where you expect it to. If you must keep clears, add enough delays to allow you to read this information.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: