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

#1 2013-04-28 14:35:56

birdlover2010
New Scratcher
Registered: 2013-04-24
Posts: 1

Need help changing score up or down based on costume number

Hello, I am new to scratch and have spent a couple of weeks building a game. In my game, I have ghosts that switch from green to white. When the character touches the green ghost and presses the spacebar, I want the score to increase. When the character touches the white ghost and presses the spacebar, I want the score to decrease. I set the character when space key pressed to broadcast touching something good and broadcast touching something bad.

Here is the script when touching the green ghost...

When I receive touching something good
If touching character
     wait until costume # 1
     change score by 1
     hide
     wait 1 sec
     broadcast new green ghost
end if

Here is the script when touching the white ghost...

When I receive touching something bad
If touching character
     wait until costume # 2
     broadcast character saying "you lost points"
     change score by -1
     hide
     wait 1 sec
     broadcast new white ghost
end if

When I go to run the game and press the spacebar, both scripts turn white. The character makes the announcement whether or not it is on a green or white ghost. The points seem to work though.

Also, I have different backgrounds. The ghosts are only to appear on one of the backgrounds. If I don't get rid of all the ghosts before changing the background, they are still there on the next background. I checked my script for hiding them with different backgrounds and it works correctly. This problem must all be related to the above script.

Any help I could get on resolving this issue would be greatly appreciated.

Offline

 

#2 2013-04-29 12:49:25

cauzality
New Scratcher
Registered: 2013-03-19
Posts: 44

Re: Need help changing score up or down based on costume number

one problem is probably the "wait until costume #"; i don't know what that's supposed to do.

i'd try something like:

when [space v] key pressed
if <touching [character v]?>
   if <(color) = [green]>
      broadcast [good touch v]
   end
   if <(color) = [white]>
      broadcast [bad touch v]
   end 
end

when I receive [good touch v]
hide
change [score v] by [1]
wait [1] secs
goto x: (pick random [-220] to [220]) y: (pick random [-160] to [160])
show

when I receive [bad touch v]
hide
change [score v] by [-1]
wait [1] secs
goto x: (pick random [-220] to [220]) y: (pick random [-160] to [160])
show
*this would be the script for each ghost. you could set a variable (use: for this sprite only) which is "green" when they are green and "white" if white. your character can do different things when it receives the "bad touch" and "good touch" broadcasts in its own scripts.

change this if the assumptions im making aren't what you're doing, but this will make the ghost reappear randomly on the screen after 1 sec after it's been touched.

about the backgrounds you could give the ghosts stacks like these:
when i receive [initialize ghost level v]
show

when i receive [leave ghost level v]
hide
******
best of luck

Offline

 

Board footer