This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-02-09 16:41:32

Garr8test
New Scratcher
Registered: 2012-02-08
Posts: 15

show/hide

im making a simulation game with different civilizations from real life. I made this box to show scores. I want to make it to where that when you click space it will either show or hide. How can i do this?

Offline

 

#2 2012-02-09 16:49:21

Snowdrift
Scratcher
Registered: 2011-06-22
Posts: 500+

Re: show/hide

when gf clicked
hide variable [variable]
show variable [variable]
Theese blocks ^

Last edited by Snowdrift (2012-02-09 16:50:10)

Offline

 

#3 2012-02-09 16:50:27

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: show/hide

when gf clicked
set [space v] to (0)

when [space v] key pressed
set [space v] to <(1) - (space)>
if <(space) = (1)>
    show variable [score v]
else
    hide variable [score v]
end
Is that what you want/mean?

Offline

 

#4 2012-02-09 16:52:30

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: show/hide

Assuming that your score is shown in a variable called score:

(score)
Make another variable:
(ScoreShown)
Then:
When [space v] key pressed
if <(ScoreShown) = [0]>
show variable [score v]
set (ScoreShown) to [1]
else
hide variable [score v]
set (ScoreShown) to [0]
end

EDIT: Aww I was late... also that thing Magnie did with set space to 1 - space is good since it reduces blocks needed overall by one. You would use it instead of scoreshown and after the if/else.

Last edited by Smozzick (2012-02-09 16:54:25)


http://i50.tinypic.com/ded8m.png

Offline

 

#5 2012-02-09 16:53:24

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: show/hide

You will need a sprite-only variable ( I named it H/S )

{Start of script}
When [Space key pressed]
If <(H/S)=Hide>
  Set [H/S] to (Show)
  Show [Variable]
  Stop Script
  {End of if}
If <(H/S)=Show>
  Set [H/S] to (Hide)
  Hide [Variable]
  Stop Script
  {End of if}
{End of script}

EDIT: Or you could do this

{Start of script}
When [Space key pressed]
If <(H/S)=Hide>
  Set [H/S] to (Show)
  Show [Variable]
  {End of if}
else
  Set [H/S] to (Hide)
  Hide [Variable]
  {End of else}
{End of script}

Last edited by laptop97 (2012-02-09 16:56:54)

Offline

 

#6 2012-02-09 17:26:41

Garr8
Scratcher
Registered: 2011-08-10
Posts: 1000+

Re: show/hide

thx but i found an alternative      i am going to use when h pressed hide it when s is pressed show it


What I scored on Pokemon Quiz: Porygon

Offline

 

#7 2012-02-09 19:06:58

GiovanH
New Scratcher
Registered: 2012-02-07
Posts: 2

Re: show/hide

The easiest way is this:

When space pressed
Forever
Show Variable
Wait until space pressed
Hide Variable
/Forever

Offline

 

#8 2012-02-09 20:02:17

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: show/hide

When [space v] key pressed
if <(variable) = [1] >
hide variable [whatever]
set [variable] to 0
else
show variable [whatever]
set [variable] to 1

Last edited by CheeseMunchy (2012-02-09 20:06:42)


6418,

Offline

 

#9 2012-02-10 17:01:11

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: show/hide

GiovanH wrote:

The easiest way is this:

When space pressed
Forever
Show Variable
Wait until space pressed
Hide Variable
/Forever

So, when I press space it begins the script and shows the variable. Then, I press space again, and it hides the variable. But it loops, so it shows it again.

This way works:

when gf clicked
forever
show variable [var v]
wait until <key [space v] pressed?>
wait until <not <key [space v] pressed?>>
hide variable [var v]
wait until <key [space v] pressed?>
wait until <not <key [space v] pressed?>>
Or this way:
when gf clicked
hide variable [var v]

when key [space v] pressed
wait until <not <key [space v] pressed?>>
show variable [var v]
wait until <key [space v] pressed?>
wait until <not <key [space v] pressed?>>
hide variable [var v]

Last edited by rdococ (2012-02-10 17:04:11)

Offline

 

Board footer