Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help? How can i make a character use a sword against a Sprite?
- Colors-of-Code
-
Scratcher
11 posts
Help? How can i make a character use a sword against a Sprite?
I'm making a dungeon explorer game and i was wondering how to make it when he picks up the sword and it goes in his inventory, and he presses space to use the sword it kills the monster?
i've already done this but it doesn't work.
___________________________________________________________________________________
Thx in advance for anyone who helps.
i've already done this but it doesn't work.
when green flag clickedBut that didn't work. what that is supposed to do is when the flag is clicked forever it waits for Sprite 1 key space to be pressed and touching Monster that then Broadcast's Hit Monster when Monster receives Hit monster it hides but. that never works.
forever
if <<touching [ Monster] ?> and <key [ Space] pressed?>> then
broadcast [ Hit Monster]
___________________________________________________________________________________
Thx in advance for anyone who helps.

- footsocktoe
-
Scratcher
1000+ posts
Help? How can i make a character use a sword against a Sprite?
I'm making a dungeon explorer game and i was wondering how to make it when he picks up the sword and it goes in his inventory, and he presses space to use the sword it kills the monster?
i've already done this but it doesn't work.when green flag clickedBut that didn't work. what that is supposed to do is when the flag is clicked forever it waits for Sprite 1 key space to be pressed and touching Monster that then Broadcast's Hit Monster when Monster receives Hit monster it hides but. that never works.
forever
if <<touching [ Monster] ?> and <key [ Space] pressed?>> then
broadcast [ Hit Monster]
___________________________________________________________________________________
Thx in advance for anyone who helps.
It depends on what else the “hit monster” message does. Since it is in a forever loop it will be broadcast dozens of times whenever the condition is met. So take that into account.
- Colors-of-Code
-
Scratcher
11 posts
Help? How can i make a character use a sword against a Sprite?
_______________________________________________________I'm making a dungeon explorer game and i was wondering how to make it when he picks up the sword and it goes in his inventory, and he presses space to use the sword it kills the monster?
i've already done this but it doesn't work.when green flag clickedBut that didn't work. what that is supposed to do is when the flag is clicked forever it waits for Sprite 1 key space to be pressed and touching Monster that then Broadcast's Hit Monster when Monster receives Hit monster it hides but. that never works.
forever
if <<touching [ Monster] ?> and <key [ Space] pressed?>> then
broadcast [ Hit Monster]
___________________________________________________________________________________
Thx in advance for anyone who helps.
It depends on what else the “hit monster” message does. Since it is in a forever loop it will be broadcast dozens of times whenever the condition is met. So take that into account.
yes that is what it is supposed it will constantly be on the loop cause there are multiple monsters. since there are at least one for each level.

- deck26
-
Scratcher
1000+ posts
Help? How can i make a character use a sword against a Sprite?
What @footsocktoe means is it will happen 30 times a second and since you're using a broadcast the receiver script probably won't have time to complete before it is restarted. So broadcast and wait may be better and you may prefer not to let a broadcast happen for, say, a quarter second after the previous one._______________________________________________________I'm making a dungeon explorer game and i was wondering how to make it when he picks up the sword and it goes in his inventory, and he presses space to use the sword it kills the monster?
i've already done this but it doesn't work.when green flag clickedBut that didn't work. what that is supposed to do is when the flag is clicked forever it waits for Sprite 1 key space to be pressed and touching Monster that then Broadcast's Hit Monster when Monster receives Hit monster it hides but. that never works.
forever
if <<touching [ Monster] ?> and <key [ Space] pressed?>> then
broadcast [ Hit Monster]
___________________________________________________________________________________
Thx in advance for anyone who helps.
It depends on what else the “hit monster” message does. Since it is in a forever loop it will be broadcast dozens of times whenever the condition is met. So take that into account.
yes that is what it is supposed it will constantly be on the loop cause there are multiple monsters. since there are at least one for each level.
- Colors-of-Code
-
Scratcher
11 posts
Help? How can i make a character use a sword against a Sprite?
____________________________________What @footsocktoe means is it will happen 30 times a second and since you're using a broadcast the receiver script probably won't have time to complete before it is restarted. So broadcast and wait may be better and you may prefer not to let a broadcast happen for, say, a quarter second after the previous one._______________________________________________________I'm making a dungeon explorer game and i was wondering how to make it when he picks up the sword and it goes in his inventory, and he presses space to use the sword it kills the monster?
i've already done this but it doesn't work.when green flag clickedBut that didn't work. what that is supposed to do is when the flag is clicked forever it waits for Sprite 1 key space to be pressed and touching Monster that then Broadcast's Hit Monster when Monster receives Hit monster it hides but. that never works.
forever
if <<touching [ Monster] ?> and <key [ Space] pressed?>> then
broadcast [ Hit Monster]
___________________________________________________________________________________
Thx in advance for anyone who helps.
It depends on what else the “hit monster” message does. Since it is in a forever loop it will be broadcast dozens of times whenever the condition is met. So take that into account.
yes that is what it is supposed it will constantly be on the loop cause there are multiple monsters. since there are at least one for each level.
thx very much i will try that know.



- bastiaan1200
-
Scratcher
17 posts
Help? How can i make a character use a sword against a Sprite?
Script inside your guy that fights
This should work (Tip: Dont work allot with broad cast you can do thiswith an variable to
Now add an delay in and you are done!
I hope i helped you!
when green flag clicked
forever
if <<(distance to [Guy (not monster) v]) < [50]> and <key [Space v] pressed?>> then
broadcast [Hit monster v] and wait
else
end
end
This should work (Tip: Dont work allot with broad cast you can do thiswith an variable to
when green flag clicked
forever
if <<(distance to [Guy (not monster) v]) < [50]> and <key [Space v] pressed?>> then
set [Hit.Monster v] to [1]
else
set [Hit.Monster v] to [0]
end
end
when green flag clicked
forever
if <(Hit.Monster) = [1]> then
change [Monsterhealth v] by (-10)
if <(Monsterhealth) < [1]> then
YOURSCRIPT
end
else
end
end
Now add an delay in and you are done!
I hope i helped you!
Last edited by bastiaan1200 (Aug. 1, 2016 14:41:20)
- Colors-of-Code
-
Scratcher
11 posts
Help? How can i make a character use a sword against a Sprite?
Script inside your guy that fights__________________________________when green flag clicked
forever
if <<(distance to [Guy (not monster) v]) < [50]> and <key [Space v] pressed?>> then
broadcast [Hit monster v] and wait
else
end
end
This should work (Tip: Dont work allot with broad cast you can do thiswith an variable towhen green flag clicked
forever
if <<(distance to [Guy (not monster) v]) < [50]> and <key [Space v] pressed?>> then
set [Hit.Monster v] to [1]
else
set [Hit.Monster v] to [0]
end
endwhen green flag clicked
forever
if <(Hit.Monster) = [1]> then
change [Monsterhealth v] by (-10)
if <(Monsterhealth) < [1]> then
YOURSCRIPT
end
else
end
end
Now add an delay in and you are done!
I hope i helped you!
thx very much not what i was looking for exactly but what you added will go great in the game so i'm using that know thx. (i'll put everyone who helped in the comments)
- hornbeef
-
Scratcher
34 posts
Help? How can i make a character use a sword against a Sprite?
I'm making a dungeon explorer game and i was wondering how to make it when he picks up the sword and it goes in his inventory, and he presses space to use the sword it kills the monster?are you actually touching the monster when you press space?
i've already done this but it doesn't work.when green flag clickedBut that didn't work. what that is supposed to do is when the flag is clicked forever it waits for Sprite 1 key space to be pressed and touching Monster that then Broadcast's Hit Monster when Monster receives Hit monster it hides but. that never works.
forever
if <<touching [ Monster] ?> and <key [ Space] pressed?>> then
broadcast [ Hit Monster]
___________________________________________________________________________________
Thx in advance for anyone who helps.
- Colors-of-Code
-
Scratcher
11 posts
Help? How can i make a character use a sword against a Sprite?
________________________________________________________________I'm making a dungeon explorer game and i was wondering how to make it when he picks up the sword and it goes in his inventory, and he presses space to use the sword it kills the monster?are you actually touching the monster when you press space?
i've already done this but it doesn't work.when green flag clickedBut that didn't work. what that is supposed to do is when the flag is clicked forever it waits for Sprite 1 key space to be pressed and touching Monster that then Broadcast's Hit Monster when Monster receives Hit monster it hides but. that never works.
forever
if <<touching [ Monster] ?> and <key [ Space] pressed?>> then
broadcast [ Hit Monster]
___________________________________________________________________________________
Thx in advance for anyone who helps.
yes.
- kuct
-
New Scratcher
1 post
Help? How can i make a character use a sword against a Sprite?
Help, how do i create a script that makes when touching a sword you can use it to attack enemies! PLEEAASSE HELP!
- deck26
-
Scratcher
1000+ posts
Help? How can i make a character use a sword against a Sprite?
Help, how do i create a script that makes when touching a sword you can use it to attack enemies! PLEEAASSE HELP!If the above doesn't help please create your own topic rather than necroposting and share what you currently have.
- erc122potter
-
New Scratcher
1 post
Help? How can i make a character use a sword against a Sprite?
I need a lot of help! I need to make it so when you touch the sword you can use it and i need to find out how to strike with it. hope you can help me

- deck26
-
Scratcher
1000+ posts
Help? How can i make a character use a sword against a Sprite?
I need a lot of help! I need to make it so when you touch the sword you can use it and i need to find out how to strike with it. hope you can help meCreate your own new topic rather than necroposting please and share the project.
- 5Proll
-
Scratcher
1 post
Help? How can i make a character use a sword against a Sprite?
i can not turn my sword horizontal way
- Discussion Forums
- » Help with Scripts
-
» Help? How can i make a character use a sword against a Sprite?
