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

Username:   Password: 
 RegisterRegister   
 Is it possible to have a procedure running in the background of a program?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tasty Pastry




PostPosted: Tue Jun 06, 2017 9:31 pm   Post subject: Is it possible to have a procedure running in the background of a program?

I'm making a game in Turing, and I've made a menu option for the player to bring up at any point during their play-through of the game. However I can't seem to figure out how to have the program check for the input to bring the menu up while still going through other parts of the code. It only seems like it's going through it step-by-step, and for the life of me I cannot find out how to fix this. Any suggestions?

Turing:


% Menu check

proc MenuCheck
loop
    Input.KeyDown (chars)
    if chars ('z') then
    delay (150)
        loop
            Input.KeyDown (chars)
            if chars (KEY_DOWN_ARROW) then
                MenuPick := MenuPick + 0.025
            else
                if chars (KEY_UP_ARROW) then
                    MenuPick := MenuPick - 0.025
                end if
            end if
            if MenuPick > 5 then
                MenuPick := 1
            end if
            if MenuPick < 1 then
                MenuPick := 4.5
            end if
            if MenuPick >= 1 and MenuPick < 2 then
                Pic.Draw (MenuBox1, 2, 280, picMerge)
                View.Update
            end if
            if MenuPick >= 2 and MenuPick < 3 then
                Pic.Draw (MenuBox2, 2, 280, picMerge)
                View.Update
            end if
            if MenuPick >= 3 and MenuPick < 4 then
                Pic.Draw (MenuBox3, 2, 280, picMerge)
                View.Update
            end if
            if MenuPick >= 4 and MenuPick < 5 then
                Pic.Draw (MenuBox4, 2, 280, picMerge)
                View.Update
            end if
            if chars (KEY_ENTER) then
            %do stuff
            end if
            if chars ('z') then
            exit
            end if
        end loop
        delay (150)
        Pic.Draw (MenuBlank, 2, 280, 0)
        View.Update
        exit
    end if
end loop
end MenuCheck

% Main part of the program

MenuCheck

Pic.Draw (TextBox, 160, 10, 0)
View.Update
TypewriterPrint("Hello Daanish! Is this font too big")
TypewriterPrint2 ("or too small?")



Is there such thing as a "do this and this together" command, and if there is, what is it and how do I use it?
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Jun 07, 2017 4:09 pm   Post subject: RE:Is it possible to have a procedure running in the background of a program?

The good news is, there is such a command! The bad news is, all it will give you are unexplainable bugs so it's a bad idea to use it.

Your best option I think is to create a procedure that handles only that button and include it in all parts of your code that requires that button.
Tasty Pastry




PostPosted: Wed Jun 07, 2017 5:38 pm   Post subject: Re: RE:Is it possible to have a procedure running in the background of a program?

Insectoid @ Wed Jun 07, 2017 4:09 pm wrote:
The good news is, there is such a command! The bad news is, all it will give you are unexplainable bugs so it's a bad idea to use it.

Your best option I think is to create a procedure that handles only that button and include it in all parts of your code that requires that button.


Yeah, but... I need that button to run all the time. Throughout the whole entire game.

Also, I've come across another problem. I thought I could use process, but I needed to figure out a way to hide the image without cls'ing the whole screen, so I used sprites. I also need View.Update on some parts, but for some reason the screen freezes just after I call the menu process.

Heres the process:

Turing:


process MenuCheck
    loop   
        Input.KeyDown (chars)
        if chars ('z') then
            delay (150)
            loop
                Input.KeyDown (chars)
                if chars (KEY_DOWN_ARROW) then
                    MenuPick := MenuPick + 0.0005
                else
                    if chars (KEY_UP_ARROW) then
                        MenuPick := MenuPick - 0.0005
                    end if
                end if
                if MenuPick > 5 then
                    MenuPick := 1
                end if
                if MenuPick < 1 then
                    MenuPick := 4.5
                end if
                if MenuPick >= 1 and MenuPick < 2 then
                View.Set ("nooffscreenony")
                    Sprite.Hide (MenuBoxSprite4)
                    Sprite.Hide (MenuBoxSprite3)
                    Sprite.Hide (MenuBoxSprite2)
                    Sprite.Show (MenuBoxSprite1)
                View.Set ("offscreenonly")
                end if
                if MenuPick >= 2 and MenuPick < 3 then
                View.Set ("nooffscreenony")
                    Sprite.Hide (MenuBoxSprite4)
                    Sprite.Hide (MenuBoxSprite3)
                    Sprite.Hide (MenuBoxSprite1)
                    Sprite.Show (MenuBoxSprite2)
                View.Set ("offscreenonly")
                end if
                if MenuPick >= 3 and MenuPick < 4 then
                View.Set ("nooffscreenony")
                    Sprite.Hide (MenuBoxSprite4)
                    Sprite.Hide (MenuBoxSprite2)
                    Sprite.Hide (MenuBoxSprite1)
                    Sprite.Show (MenuBoxSprite3)
                View.Set ("offscreenonly")   
                end if
                if MenuPick >= 4 and MenuPick < 5 then
                View.Set ("nooffscreenony")
                    Sprite.Hide (MenuBoxSprite2)
                    Sprite.Hide (MenuBoxSprite3)
                    Sprite.Hide (MenuBoxSprite1)
                    Sprite.Show (MenuBoxSprite4) 
                View.Set ("offscreenonly")     
                end if
                if chars (KEY_ENTER) then
                    %do stuff
                end if
                if chars ('z') then
                    exit
                end if
            end loop
            delay (150)
            View.Set ("nooffscreenony")
            Sprite.Hide (MenuBoxSprite4)
            Sprite.Hide (MenuBoxSprite3)
            Sprite.Hide (MenuBoxSprite1)
            Sprite.Hide (MenuBoxSprite2)
            View.Set ("offscreenonly")             
        end if
    end loop
end MenuCheck



...And heres the actual code where I call it.

Turing:

loop
Input.KeyDown (chars)
delay (1000)
Font.Draw ("Deceased", 570, 620, font, white)
delay (500)
Logo
exit when chars (KEY_ENTER)
end loop

View.Set ("offscreenonly")

cls % Freezes up right around here

View.Update

fork MenuCheck

Pic.Draw (TextBox, 160, 10, picMerge)
View.Update
fontPositionChoosex := 278
fontPositionChoosey := 185
TypewriterPrintSlow ("....")


It only continues if I press the 'z' key again, then enter, otherwise it just freezes and stays there.
Insectoid




PostPosted: Wed Jun 07, 2017 8:07 pm   Post subject: RE:Is it possible to have a procedure running in the background of a program?

See, this is why you don't use processes. The program will not pause when you hit the z key. The delay in your process will only delay *that process*. The rest of the program will continue without it. This method will not work. The only way to do what you're trying to do is to manually program that button/keypress in everywhere that you need it. There is no alternative. That means you must always be running input.keydown every few milliseconds. You cannot have any long delays. All of your loops must execute quickly. You will probably have to completely restructure all of your logic and code to make this button work. There is no quick fix.
Tasty Pastry




PostPosted: Wed Jun 07, 2017 8:25 pm   Post subject: Re: RE:Is it possible to have a procedure running in the background of a program?

Insectoid @ Wed Jun 07, 2017 8:07 pm wrote:
See, this is why you don't use processes. The program will not pause when you hit the z key. The delay in your process will only delay *that process*. The rest of the program will continue without it. This method will not work. The only way to do what you're trying to do is to manually program that button/keypress in everywhere that you need it. There is no alternative. That means you must always be running input.keydown every few milliseconds. You cannot have any long delays. All of your loops must execute quickly. You will probably have to completely restructure all of your logic and code to make this button work. There is no quick fix.


Yeah, I don't need the program to be paused while the Menu is running. The problem is that as soon as the process is called, the program freezes unless I hit z and then z again, then press the enter key.
Insectoid




PostPosted: Thu Jun 08, 2017 4:44 am   Post subject: RE:Is it possible to have a procedure running in the background of a program?

I don't know why it's freezing, and it's not worth my time to find out as long as you are using processes.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: