I am currently working one a First Person Shooter using the Scratch language, and up till about yesterday everything was working very smoothly. however, there seems to be an issue when triggering my cherub monster when using a *when I receive {broadcast}* block. i have it set up so that it looks like this:
*when I receive {broadcast}
if {key} pressed
etc.
unfortunately, it will only perform the rest of its functions (etc.) if miraculously the {key} is pressed at the exact same moment as it reveives the {broadcast} So far I have found no way to create a *if x has occured* *when x is pressed* setup that is successful.
Does anyone have suggestions on how to do this or something similar? A huge amount of time and effort has gone into this project and I don't want to have change its settup and overall complexity now if it can be avoided...
Thanks!
Offline
We need to see what sends the broadcast to understand what is going on here. But what you can do is use a variable as a boolean. (What I do is make a variable, make it 0 for false, and 1 for true.) That way, when "event x" occurs, you set the variable to 1. And you can change "if (key) pressed" to "if (variable) = 1"
But...
Why are you putting an if block in a broadcast receiver? I normally do all logic (control blocks) around the "broadcast" block, unless the broadcast is called under more than one circumstance (not recommended).
eyra
Offline
AngelEyra: The broadcast is sent by an enemy after it is shot and killed. Then it is picked up by the next enemy in line. Then when the player moves forward, as long as that broadcast has been received, the next enemy will appear. The variable settup does work, I've tried it, but its not as smooth as I'd like it to be. In earlier situations in the game, I've found that using broadcasts often works as a smoother equivalent to variable manipulations--otherwise I would just use the variable as you suggested. Thanks, tho.
Offline
Change it to a wait until block.
When I recieve [broadcast]
wait until (key pressed)
(Spawn new monster)
Offline
Sawman3 wrote:
thanx--im an idiot for not thinking of that...
You're only an idiot if you keep banging your head against a wall when there is help available. Frequently the most obvious things - in hindsight - are the most difficult to see.
Offline
Well, I guess I know that there's a "wait until" block now
.
Offline
also if you dont want to watch a tutorial: for a function on a sprite (for example, when key right arrow pressed) select the block that says *broadcast* followed by a blank space the word new. type in whatever you want the name of that broadcast to be. then for another sprite, or even the same one, you can choose a *when I receive (broadcast)* block and have it perform whatever action you want when it revieves that message. in my experience, they seem to work smoother than variable manipulations and are more versatile. Hope that helps!
Offline