Discuss Scratch

DIMITRIS6023
Scratcher
6 posts

Can you help me?

Hello, Im working on a project that it is a shooter game,but im trying to fix a bug but I can't.

Here's the code of the sprite that it has a bug

Other sprite's code:

when I receive [ v]
forever
if <touching [mouse pointer v] ?> then
set [costume v] to [1]


else
set [costume v] to [0]
end
end




The sprite that i think it has a bug
when green flag clicked
forever
switch costume to [(costume) v]
end

please help

Last edited by DIMITRIS6023 (Aug. 9, 2018 18:57:01)

DIMITRIS6023
Scratcher
6 posts

Can you help me?

also this is my first time joining forums so i made some faults

in the switch costume to (costume) it should be the variable costume in the end
and the sprite's costumes are named 1 and 0
thanks for reading
NilsTheBest
Scratcher
1000+ posts

Can you help me?

Could you say what you are trying to do, and what actually happens? (And perhaps share the link of the project)
I'd gladly help!

NilsTheChair | 5 years on Scratch | 4000+ posts | former wiki editor | 332nd FPC | CoR founder
RokCoder
Scratcher
1000+ posts

Can you help me?

DIMITRIS6023 wrote:

also this is my first time joining forums…

Welcome Generally, it's easier for people to help you with bugs if you share the project rather than just snippets from it.

One possibility is that you're declaring the costume variable as for this sprite only rather than for all sprites?


Scratch dabbling for fun…

NilsTheBest
Scratcher
1000+ posts

Can you help me?

RokCoder wrote:

DIMITRIS6023 wrote:

also this is my first time joining forums…

Welcome Generally, it's easier for people to help you with bugs if you share the project rather than just snippets from it.

One possibility is that you're declaring the costume variable as for this sprite only rather than for all sprites?

Yes, I was thinking that too
when I receive [ v]
forever
if <touching [mouse pointer v] ?> then
switch costume to [costume1 v]


else
switch costume to [costume2 v]
end
end
Maybe this is what you were trying to do

Last edited by NilsTheBest (Aug. 9, 2018 19:48:54)


NilsTheChair | 5 years on Scratch | 4000+ posts | former wiki editor | 332nd FPC | CoR founder
deck26
Scratcher
1000+ posts

Can you help me?

A more efficient method is

forever
switch costume to [costume2 v]
wait until <touching [mouse-pointer v]>
switch costume to [costume1 v]
wait until <not <touching [mouse-pointer v]>>

end
This is because switching costume is giving Scratch work to do even if you switch to the current costume so it's better to only do so when the costume actually changes.

Powered by DjangoBB