Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » I need help making a chat system.
- zablonb2424
-
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:
My browser / operating system: Android Linux 10, Chrome 133.0.0.0, No Flash version detected
Ground:
when green flag clickedPlayer:
set [pixelate v] effect to (10)
when green flag clickedMobile:
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
when green flag clickedRightMobile:
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
when green flag clickedLeftMobile:
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]
when green flag clickedUpMobile:
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]
when green flag clickedChatMobile:
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]
when green flag clickedStage:
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]
when I receive [chat msg v]Also, here's my browser data if it's important:
ask [Say something in chat...] and wait
set [question? v] to [1]
My browser / operating system: Android Linux 10, Chrome 133.0.0.0, No Flash version detected
- _0xfffrog-
-
100+ posts
I need help making a chat system.
Due to a bug of Scratch,
(maybe “keyup” event of javascript is not sent)
So before asking, wait until the key is released.
<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
-
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
-
93 posts
I need help making a chat system.
Thank you, this helped me fix my project. 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]
- Discussion Forums
- » Help with Scripts
-
» I need help making a chat system.