Discuss Scratch

zablonb2424
Scratcher
93 posts

I need help making a chat system.

I'm trying to make a chat system so the player can talk to NPCs in the game, but it's not working out. It keeps asking to type something in the chat. Here is the code for the sprites:
Ground:
when green flag clicked
set [pixelate v] effect to (10)
Player:
when green flag clicked
forever
change y by (speed y)
end
when green flag clicked
set [pixelate v] effect to (10)
set rotation style [left-right v]
point in direction (90)
set [speed y v] to (0)
forever
if <(y position) < (-15)> then
set y to (-15)
end
if <(-15) < (y position)> then
repeat until <(speed y) = (1)>
set [speed y v] to ((speed y) / (2))
switch costume to [jump v]
wait (0) secs
end
set [speed y v] to (-1)
repeat until <<(y position) = (-15)> or <(y position) < (-15)>>
set [speed y v] to ((speed y) * (2))
switch costume to [jump v]
wait (0) secs
end
set y to (-15)
set [speed y v] to (0)
switch costume to [idle v]
end
end
when green flag clicked
set [walk v] to (1)
switch costume to [idle v]
forever
if <<key [right arrow v] pressed?> or <(right?) = (1)>> then
repeat until <not <<key [right arrow v] pressed?> or <(right?) = (1)>>>
point in direction (90)
switch costume to (join [walk] (walk))
move (3) steps
wait (0) secs
if <(walk) = [15]> then
set [walk v] to [0]
end
end
switch costume to [idle v]
else
if <<key [left arrow v] pressed?> or <(left?) = [1]>> then
repeat until <not <<key [left arrow v] pressed?> or <(left?) = [1]>>>
point in direction (-90)
switch costume to (join [walk] (walk))
move (3) steps
wait (0) secs
if <(walk) = [15]> then
set [walk v] to [0]
end
end
switch costume to [idle v]
else
if <<<key [up arrow v] pressed?> or <key [space v] pressed?>> or <(up?) = [1]>> then
if <(y position) = [-15]> then
set [speed y v] to [32]
end
else
if <key (join [/] []) pressed?> then
broadcast [chat msg v]
else

end
end
end
end
when I receive [chat msg v]
set [question? v] to [0]
repeat until <(question?) = [1]>
say [.]
wait (0.1) secs
say [..]
wait (0.1) secs
say [...]
wait (0.1) secs
end
broadcast [SAY IT v]
when I receive [SAY IT v]
say (answer) for (5) secs
Mobile:
when green flag clicked
set [pixelate v] effect to (10)
set [ghost v] effect to (50)
switch costume to [nah im good v]
when this sprite clicked
next costume
RightMobile:
when green flag clicked
set [pixelate v] effect to (10)
set [ghost v] effect to (100)
set [right? v] to [0]
forever
if <([costume # v] of [Mobile v]) = [2]> then
show
else
hide
end
end
when this sprite clicked
repeat until <not <<touching [mouse-pointer v] ?> and <mouse down?>>>
set [right? v] to [1]
end
set [right? v] to [1]
LeftMobile:
when green flag clicked
set [pixelate v] effect to (10)
set [ghost v] effect to (100)
set [left? v] to [0]
forever
if <([costume # v] of [Mobile v]) = [2]> then
show
else
hide
end
end
when this sprite clicked
repeat until <not <<touching [mouse-pointer v] ?> and <mouse down?>>>
set [left? v] to [1]
end
set [left? v] to [1]
UpMobile:
when green flag clicked
set [pixelate v] effect to (10)
set [ghost v] effect to (100)
set [up? v] to [0]
forever
if <([costume # v] of [Mobile v]) = [2]> then
show
else
hide
end
end
when this sprite clicked
repeat until <not <<touching [mouse-pointer v] ?> and <mouse down?>>>
set [up?? v] to [1]
end
set [up? v] to [1]
ChatMobile:
when green flag clicked
set [pixelate v] effect to (10)
set [ghost v] effect to (100)
forever
if <([costume # v] of [Mobile v]) = [2]> then
show
else
hide
end
end
when this sprite clicked
broadcast [chat msg v]
Stage:
when I receive [chat msg v]
ask [Say something in chat...] and wait
set [question? v] to [1]
Also, here's my browser data if it's important:
My browser / operating system: Android Linux 10, Chrome 133.0.0.0, No Flash version detected
_0xfffrog-
Scratcher
100+ posts

I need help making a chat system.

Due to a bug of Scratch,
<key (join [\\] []) pressed?>
will always be true when the input dialog is displayed.
(maybe “keyup” event of javascript is not sent)

So before asking, wait until the key is released.
wait until <not <key (join [\\] []) pressed?>>
broadcast [chat msg v]
deck26
Scratcher
1000+ posts

I need help making a chat system.

Rather than create all of that in Scratchblocks where there's a good chance you'll make an error it is better to share the project so we can see the code in context and actually experiment with it.
zablonb2424
Scratcher
93 posts

I need help making a chat system.

_0xfffrog- wrote:

Due to a bug of Scratch,
<key (join [\\] []) pressed?>
will always be true when the input dialog is displayed.
(maybe “keyup” event of javascript is not sent)

So before asking, wait until the key is released.
wait until <not <key (join [\\] []) pressed?>>
broadcast [chat msg v]
Thank you, this helped me fix my project.

Powered by DjangoBB