Discuss Scratch

50Fingers
Scratcher
59 posts

How to Code to open and close another window

Hi All,

I would like to code a sprite that open up a window and when the user clicks on it again, the window closes.

Can anyone help?

Uniquename1
Scratcher
100+ posts

How to Code to open and close another window

It wouldn't be an actual window on your computer but you can show and hide a sprite that looks like a box/ window within the scratch viewing window.

You could either have another sprite as an icon to click on to open said ‘window’ or press a keyboard button to open it. Specific details depend on what you want on it and such but basically hide and show a sprite. And use that sprite or multiple sprites as your window.

It would be multiple sprites if for example you had more buttons and such in the window.

Last edited by Uniquename1 (Aug. 10, 2017 00:52:30)

MineLox92Videos
Scratcher
100+ posts

How to Code to open and close another window

So you have your window (In the game), and you have a button:

whenthisspriteclicked In this case, the buttonifopen=truethenhidesetopentofalseelseifopen=falsethenshowsetopentotrue

Last edited by MineLox92Videos (Aug. 10, 2017 00:53:03)

50Fingers
Scratcher
59 posts

How to Code to open and close another window

MineLox92Videos wrote:

So you have your window (In the game), and you have a button:

whenthisspriteclicked In this case, the buttonifopen=truethenhidesetopentofalseelseifopen=falsethenshowsetopentotrue

Hi MineLox92Videos!

Thanks for reading my post and sharing the code.

I have tried and applied on my project which is about a business simulation game aka theme park tycoon.

However, how do I code to make the window appears after applying the first script to a button which user needs to click on before the window appears?

My Project: https://scratch.mit.edu/projects/170469472/

Last edited by 50Fingers (Aug. 10, 2017 01:21:23)

MineLox92Videos
Scratcher
100+ posts

How to Code to open and close another window

50Fingers wrote:

MineLox92Videos wrote:

So you have your window (In the game), and you have a button:

whenthisspriteclicked In this case, the buttonifopen=truethenhidesetopentofalseelseifopen=falsethenshowsetopentotrue

Hi MineLox92Videos!

Thanks for reading my post and sharing the code.

I have tried and applied on my project which is about a business simulation game aka theme park tycoon.

However, how do I code to make the window appears after applying the first script to a button which user needs to click on before the window appears?

My Project: https://scratch.mit.edu/projects/170469472/
Wait, the user has to type the code to open it?
MineLox92Videos
Scratcher
100+ posts

How to Code to open and close another window

Never mind, you have to set the variable to false, once, manually.
50Fingers
Scratcher
59 posts

How to Code to open and close another window

MineLox92Videos wrote:

Never mind, you have to set the variable to false, once, manually.

The user need not type any code to open the button. They just need to click on the button to open a window.

If you have seen my project, I only have one category in this tycoon game. The category is called scenery. Users are to click on Scenery to open up a menu of sprites that they can place on their theme park ground.

I don't quite understand how that script works in order to allow the user to click on the button to open a window and then click on it again to close the window. Appreciate if you could explain how did you form this script?

whenthisspriteclickedifopen=truethenhidesetopentofalseelseifopen=falsethenshowsetopentotrue

Last edited by 50Fingers (Aug. 10, 2017 01:53:56)

MineLox92Videos
Scratcher
100+ posts

How to Code to open and close another window

50Fingers wrote:

MineLox92Videos wrote:

Never mind, you have to set the variable to false, once, manually.

The user need not type any code to open the button. They just need to click on the button to open a window.

If you have seen my project, I only have one category in this tycoon game. The category is called scenery. Users are to click on Scenery to open up a menu of sprites that they can place on their theme park ground.

I don't quite understand how that script works in order to allow the user to click on the button to open a window and then click on it again to close the window. Appreciate if you could explain how did you form this script?

whenthisspriteclicked Waits for the sprite to be clickedifopen=truethenhidesetopentofalse Sets variable to false, which can trigger the next script, if it's clicked againelseifopen=falsethenshowsetopentotrue Sets variable to true, which can trigger the script above, if it's clicked again Reports if the window is closed Reports if the window is open
Also, I forgot to mention have this:
whenclickedsetopentofalse Allows you to open the window, you had it set to 0, meaning that script is, in a way, innactive

Last edited by MineLox92Videos (Aug. 10, 2017 02:54:32)

50Fingers
Scratcher
59 posts

How to Code to open and close another window

MineLox92Videos wrote:

50Fingers wrote:

MineLox92Videos wrote:

Never mind, you have to set the variable to false, once, manually.

The user need not type any code to open the button. They just need to click on the button to open a window.

If you have seen my project, I only have one category in this tycoon game. The category is called scenery. Users are to click on Scenery to open up a menu of sprites that they can place on their theme park ground.

I don't quite understand how that script works in order to allow the user to click on the button to open a window and then click on it again to close the window. Appreciate if you could explain how did you form this script?

whenthisspriteclicked Waits for the sprite to be clickedifopen=truethenhidesetopentofalse Sets variable to false, which can trigger the next script, if it's clicked againelseifopen=falsethenshowsetopentotrue Sets variable to true, which can trigger the script above, if it's clicked again Reports if the window is closed Reports if the window is open
Also, I forgot to mention have this:
whenclickedsetopentofalse Allows you to open the window, you had it set to 0, meaning that script is, in a way, innactive


Thank you! I manage to make the idea I wanted work somehow. However I am not sure where should I always place those two scripts at?

MineLox92Videos
Scratcher
100+ posts

How to Code to open and close another window

50Fingers wrote:

MineLox92Videos wrote:

50Fingers wrote:

MineLox92Videos wrote:

Never mind, you have to set the variable to false, once, manually.

The user need not type any code to open the button. They just need to click on the button to open a window.

If you have seen my project, I only have one category in this tycoon game. The category is called scenery. Users are to click on Scenery to open up a menu of sprites that they can place on their theme park ground.

I don't quite understand how that script works in order to allow the user to click on the button to open a window and then click on it again to close the window. Appreciate if you could explain how did you form this script?

whenthisspriteclicked Waits for the sprite to be clickedifopen=truethenhidesetopentofalse Sets variable to false, which can trigger the next script, if it's clicked againelseifopen=falsethenshowsetopentotrue Sets variable to true, which can trigger the script above, if it's clicked again Reports if the window is closed Reports if the window is open
Also, I forgot to mention have this:
whenclickedsetopentofalse Allows you to open the window, you had it set to 0, meaning that script is, in a way, innactive


Thank you! I manage to make the idea I wanted work somehow. However I am not sure where should I always place those two scripts at?

Anywhere.
50Fingers
Scratcher
59 posts

How to Code to open and close another window

Thanks for your reply!

I have applied the scripts to the sprites which I want the open and close window interaction to happen.

I have a sprite which is called News. I want the user to click on it and the daily events and weather forecast in the news would pick randomly. I could not make make it appear and hide the same time when the News sprite.

Could you help?

My Project: https://scratch.mit.edu/projects/170469472/

Last edited by 50Fingers (Aug. 10, 2017 23:47:43)

MineLox92Videos
Scratcher
100+ posts

How to Code to open and close another window

50Fingers wrote:

Thanks for your reply!

I have applied the scripts to the sprites which I want the open and close window interaction to happen.

I have a sprite which is called News. I want the user to click on it and the daily events and weather forecast in the news would pick randomly. I could not make make it appear and hide the same time when the News sprite.

Could you help?

My Project: https://scratch.mit.edu/projects/170469472/
I tried and I'm lost. Sorry
aGlitchyFox
Scratcher
1 post

How to Code to open and close another window

This helped alot
deck26
Scratcher
1000+ posts

How to Code to open and close another window

aGlitchyFox wrote:

This helped alot
No need to necropost to say so though.
RAYBOI123451
Scratcher
1 post

How to Code to open and close another window

just how do I open another window, but not in scratch, but on the computer?

Powered by DjangoBB