Discuss Scratch

eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

Hi. I have a project whereby I want to change the background when space is pressed, but only when the text on the screen is less than 1 character or equal to 0 characters. I've tried defining my variable but it doesn't seem to work.

Last edited by eel9284 (Jan. 13, 2019 04:50:16)

computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

Oh welcome to scratch! Here is the solution:

whenspacekeypressediflengthoftext=0thenswitchbackdropto*fill this in*

eel9284 wrote:

… but only when the text on the screen is less than 1 character or equal to 0 characters …

Please elaborate on this. In the code snippet above, I am assuming you are storing the text in a variable.

Hope this helps!
eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

No. I don't know how to store it in a variable yet. When the game starts the character says hi and some text. He then tells you to press the space button to make unto the next image. but the space bar can be pressed while he's still talking.

Last edited by eel9284 (Jan. 13, 2019 04:56:47)

computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

eel9284 wrote:

No. I don't know how to store it in a variable yet. When the game starts the character says hi and some text. He then tells you to press the space button to make unto the next image. but the space bar can be pressed while he's still talking.

You are welcome! -EDIT

Ha you keep editing ur post lol

Last edited by computerboy12345 (Jan. 13, 2019 04:57:46)

eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

Sorry, but how do you store the text in a variable, please? I get what you're saying.
computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

eel9284 wrote:

No. I don't know how to store it in a variable yet. When the game starts the character says hi and some text. He then tells you to press the space button to make unto the next image. but the space bar can be pressed while he's still talking.

Show me a link to the project for me to help. I need to understand what is going on.
eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

eel9284 wrote:

Sorry, but how do you store the text in a variable, please? I get what you're saying.

First off…can you stop editing your post and make new posts?

Go under the variable tab, and click “Make a Variable”. Type in the name of the variable. Then use a block like this in your script:

set*variable*toANYTHING YOU WANT HERE

Alternatively, you may use what is called a reporter block. An example of one of these is here:
timer

Now let's say you have a variable containing a string called “ducky”. To, for example, make a sprite say what is contained in a variable, just drag one of these round blocks into the spot where you would normally type in things. Like this:

sayvariable

Guess what the sprite would say. “ducky” is the correct answer. Hope this helped!

Last edited by computerboy12345 (Jan. 13, 2019 05:08:55)

eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

Sorry for editing. Was a mistake.
computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

eel9284 wrote:

Sorry for editing. Was a mistake.

Oh, it's just fine.
computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

eel9284 wrote:

https://scratch.mit.edu/projects/279189872/

You need to share the project before I can see it.
eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

computerboy12345 wrote:

eel9284 wrote:

Sorry, but how do you store the text in a variable, please? I get what you're saying.

First off…can you stop editing your post and make new posts?

Go under the variable tab, and click “Make a Variable”. Type in the name of the variable. Then use a block like this in your script:

set*variable*toANYTHING YOU WANT HERE

Alternatively, you may use what is called a reporter block. An example of one of these is here:
timer

Now let's say you have a variable containing a string called “ducky”. To, for example, make a sprite say what is contained in a variable, just drag one of these round blocks into the spot where you would normally type in things. Like this:

sayvariable

Guess what the sprite would say. “ducky” is the correct answer. Hope this helped!

I get you, but the problem is I'm going to be writing a lot of text. Does that mean I will need to define each text in a variable?
computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

eel9284 wrote:

computerboy12345 wrote:

eel9284 wrote:

Sorry, but how do you store the text in a variable, please? I get what you're saying.

First off…can you stop editing your post and make new posts?

Go under the variable tab, and click “Make a Variable”. Type in the name of the variable. Then use a block like this in your script:

set*variable*toANYTHING YOU WANT HERE

Alternatively, you may use what is called a reporter block. An example of one of these is here:
timer

Now let's say you have a variable containing a string called “ducky”. To, for example, make a sprite say what is contained in a variable, just drag one of these round blocks into the spot where you would normally type in things. Like this:

sayvariable

Guess what the sprite would say. “ducky” is the correct answer. Hope this helped!

I get you, but the problem is I'm going to be writing a lot of text. Does that mean I will need to define each text in a variable?

Not necessarily. I have no idea what EXACTLY you are making. I need to see it. You provided a link, but you never shared the project. In order for me to actually see it, you need to share it.

==POSSIBLE SOLUTION==
This might seem advanced, but you could set up a custom block with an argument called text. Here is what I mean:

definesaytextsaytextiflengthoftext=0thenrestofcodegoeshere

Last edited by computerboy12345 (Jan. 13, 2019 05:22:49)

eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

computerboy12345 wrote:

eel9284 wrote:

https://scratch.mit.edu/projects/279189872/

You need to share the project before I can see it.

I've shared. I'll be grateful if you can take a look at it.
eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

computerboy12345 wrote:

eel9284 wrote:

computerboy12345 wrote:

eel9284 wrote:

Sorry, but how do you store the text in a variable, please? I get what you're saying.

First off…can you stop editing your post and make new posts?

Go under the variable tab, and click “Make a Variable”. Type in the name of the variable. Then use a block like this in your script:

set*variable*toANYTHING YOU WANT HERE

Alternatively, you may use what is called a reporter block. An example of one of these is here:
timer

Now let's say you have a variable containing a string called “ducky”. To, for example, make a sprite say what is contained in a variable, just drag one of these round blocks into the spot where you would normally type in things. Like this:

sayvariable

Guess what the sprite would say. “ducky” is the correct answer. Hope this helped!

I get you, but the problem is I'm going to be writing a lot of text. Does that mean I will need to define each text in a variable?

Not necessarily. I have no idea what EXACTLY you are making. I need to see it. You provided a link, but you never shared the project. In order for me to actually see it, you need to share it.

==POSSIBLE SOLUTION==
This might seem advanced, but you could set up a custom block with an argument called text. Here is what I mean:

definesaytextsaytextiflengthoftext=0thenrestofcodegoeshere


Ok. I'll look at it. Did you take a look at the project?
computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

eel9284 wrote:

computerboy12345 wrote:

eel9284 wrote:

https://scratch.mit.edu/projects/279189872/

You need to share the project before I can see it.

I've shared. I'll be grateful if you can take a look at it.

I've highlighted all problems in the project itself. Here's a remix: https://scratch.mit.edu/projects/279202338/
computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

eel9284 wrote:

computerboy12345 wrote:

eel9284 wrote:

computerboy12345 wrote:

eel9284 wrote:

Sorry, but how do you store the text in a variable, please? I get what you're saying.

First off…can you stop editing your post and make new posts?

Go under the variable tab, and click “Make a Variable”. Type in the name of the variable. Then use a block like this in your script:

set*variable*toANYTHING YOU WANT HERE

Alternatively, you may use what is called a reporter block. An example of one of these is here:
timer

Now let's say you have a variable containing a string called “ducky”. To, for example, make a sprite say what is contained in a variable, just drag one of these round blocks into the spot where you would normally type in things. Like this:

sayvariable

Guess what the sprite would say. “ducky” is the correct answer. Hope this helped!

I get you, but the problem is I'm going to be writing a lot of text. Does that mean I will need to define each text in a variable?

Not necessarily. I have no idea what EXACTLY you are making. I need to see it. You provided a link, but you never shared the project. In order for me to actually see it, you need to share it.

==POSSIBLE SOLUTION==
This might seem advanced, but you could set up a custom block with an argument called text. Here is what I mean:

definesaytextsaytextiflengthoftext=0thenrestofcodegoeshere


Ok. I'll look at it. Did you take a look at the project?

Yes, I did!
eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

Thank you so so much
eel9284
New Scratcher
14 posts

Change Background When Space is pressed.

I'm surprised it was something so simple. Thank you again.
computerboy12345
Scratcher
100+ posts

Change Background When Space is pressed.

Oh, you are welcome!

Powered by DjangoBB