The program has a wizard and a dragon. Every time the two sprites touch one of them gets a point. The student has two variable scores, one for the dragon and one for the wizard. The score is not working. I am wondering if they are on the same layer. They don't seem to be, and I think it may be a problem. Can anyone help? In the script, each sprite has an if loop saying that if one is touching the other the score increases by one.
Offline
Could you specify exactly what is not working?
(They do not have to be on the same layer)
Try using this:
when gf clicked set [wizardscore v] to (0) forever if <touching [dragon v]?> //or wizard change [wizardscore v] by (1) wait until <not <touching [dragon v]?> > //or wizard end
Last edited by trinary (2012-03-22 14:20:43)
Offline
You could try putting these into the dragon script:
when gf clicked forever wait until <touching [wizard v]?> change [scoredragon v] by [1] wait until <not <touching [wizard v]?>>and put this into the wizard:
when gf clicked forever wait until <touching [dragon v]?> change [scorewizard v] by [1] wait until <not <touching [dragon v]?>>
Offline
You probably need to have a forever block around the if.
Offline
Mokat wrote:
scimonster wrote:
You probably need to have a forever block around the if.
Or use the
Forever If <>
Do NOT use the forever if.
I learned this the hard way:
Forever if <> endChecks if the boolean operation is true, and if it is, executes forever. It only checks true or false ONCE. This is something I hope they will fix in Scratch 2.0, as it really confuses new scratchers.
Offline
So you want it that, whoever was the one to impact gets the point. That can get tricky.
Could your student upload the project? I might be able to play around with it and get it working then.
Offline
LiquidMetal wrote:
Mokat wrote:
scimonster wrote:
You probably need to have a forever block around the if.
Or use the
Forever If <>Do NOT use the forever if.
I learned this the hard way:Forever if <> endChecks if the boolean operation is true, and if it is, executes forever. It only checks true or false ONCE. This is something I hope they will fix in Scratch 2.0, as it really confuses new scratchers.
Uh, no it doesn't. This can be proven with a simple script:
When gf clicked forever if <key [space v] pressed?> change [color v] effect by (10)You'll notice that the color only changes when the space key is pressed.
Offline
You can keep speed variables, and change the speed variable if you want to change the speed.
Wizard:
when gf clicked forever move (wizard speed) steps when gf clicked forever if <touching [dragon v]?> if <(dragon speed) < (wizard speed)> change [wizard score v] by (1) end endDragon:
when gf clicked forever move (dragon speed) steps when gf clicked forever if <touching [wizard v]?> if <(wizard speed) < (dragon speed)> change [dragon score v] by (1) end end
Offline
LiquidMetal wrote:
Mokat wrote:
scimonster wrote:
You probably need to have a forever block around the if.
Or use the
Forever If <>Do NOT use the forever if.
I learned this the hard way:Forever if <> endChecks if the boolean operation is true, and if it is, executes forever. It only checks true or false ONCE. This is something I hope they will fix in Scratch 2.0, as it really confuses new scratchers.
no, you have it the wrong way round. Most new scratchers THINK it checks the condition once then loops it forever, but it is the other way round: whenever the condition is true it runs the loop, then checks the condition again and waits until it us true before running the loop again, and it does this for ever. It is equivalent to
forever if<something> do stuff endor
forever wait until <something> do stuff
Offline
The velocity idea is clever, but not quite right...you could possibly get it to work if you used the absolute value of the velocity but I think I have a simpler way:
I'm assuming the sprites are controlled one with wasd and the other with the arrow keys, correct?
Well, in the controls of each sprite, in every if key pressed statement have a variable that changes between -1 and 1 based off either sprite that's being controlled. This will tell you the last sprite that has been moved (you can change the values to a string like "wizard" and "dragon" if you want).
My method would look something like this: in ONLY ONE of the sprites, put an if block for touching the other (I'll use the dragon):
if <touching [wizard v]?> change [dragon_score v] by (((last)+(1))/(2)) change [wizard_score v] by (((last)-(1))/(-2)) endIn this case, the variable "last" is set to 1 when the dragon moves and -1 when the wizard moves. Using those two equations, the correct variable will be changed by 1 and the other by 0.
Offline
But what if both headbang into each other?
What you should do in my opinion is the velocity method. Or you could add a new feature where you press and hold a key (different for each player) to switch to an "attack mode". This lasts for say 1 second, and when you are in attack mode and hit the other player, your score increases. Otherwise, if you you touch the other player outside attack mode, your score decreases. And attack mode needs a hefty reload period.
Last edited by Hardmath123 (2012-03-28 06:58:21)
Offline