Discuss Scratch

-Pyumo-
Scratcher
33 posts

Please Help ASAP!

i'm making a game, and i need to know how to code something! heres what i need to substitute:

when green flag clicked
if <(answer) = (join [move <] (join (any number from [1] to [10000]) [> steps]))> then
set [amount v] to (last number from [1] to [10000])
move (amount) steps
end

The PyuShop

Members:
Pyumo
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

plz halp meh

The PyuShop

Members:
Pyumo
deck26
Scratcher
1000+ posts

Please Help ASAP!

No need to bump so quickly.

So you need to ‘parse’ the input. Break it into separate words by searching for the space(s). Then you can check if the first word is a move command and use the second parameter as the number.

In pseudo code

set index to 1
set new-word to blank
repeat until index > length (input)
if letter index of input = space
add new-word to list
set new-word to blank
else
add letter to end of new-word
end
change index by 1
end repeat
if length(new-word) > 0 add new-word to list // if no space after last item you'll miss the last word without this
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

umm… i don't fully understand what you mean… bbcode allows you to do scratch blocks could you maybe do that? that would be easier to understand for me ^^

The PyuShop

Members:
Pyumo
deck26
Scratcher
1000+ posts

Please Help ASAP!

-Pyumo- wrote:

umm… i don't fully understand what you mean… bbcode allows you to do scratch blocks could you maybe do that? that would be easier to understand for me ^^
Everything I've done in pseudo code has an obvious Scratch replacement. I'm sure if you try you can do it and you'll learn more by doing it yourself than blindly copying a script.
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

i'll try!

The PyuShop

Members:
Pyumo
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

i'm really in-comprehensive… i don't know how this works… is index a variable? is space a word or like an actual space? whats the new-word thing? so sorry if this is to much questions i'm just bad at understanding things and i'm not that good at coding…heheh uhh…

The PyuShop

Members:
Pyumo
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

hmm maybe i did it… i dunno…

The PyuShop

Members:
Pyumo
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

heres what i coded:

when green flag clicked
ask [input] and wait
set [input v] to (answer)
set [index v] to [1]
set [new-word v] to []
repeat until <(index) > (length of (input))>
if <(letter (index) of (input)) = []> then
add [new-word] to [list v]
else
set [new-word v] to (join (new-word) (letter (index) of (input))
end
change [index v] by (1)
end
if <(length of (new-word)) > [0]> then
add (new-word) to [list v]
end

did i do it right?
also if so what do i do now?
if i didn't could you tell me how to fix it?

Last edited by -Pyumo- (Aug. 20, 2018 08:04:23)


The PyuShop

Members:
Pyumo
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

-Pyumo- wrote:

heres what i coded:

when green flag clicked
ask [input] and wait
set [input v] to (answer)
set [index v] to [1]
set [new-word v] to []
repeat until <(index) > (length of (input))>
if <(letter (index) of (input)) = []> then
add [new-word] to [list v]
else
set [new-word v] to (join (new-word) (letter (index) of (input))
end
change [index v] by (1)
end
if <(length of (new-word)) > [0]> then
add (new-word) to [list v]
end

did i do it right?
also if so what do i do now?
if i didn't could you tell me how to fix it?

wait i did it wrong how do i fix cause if i put “move 10 steps” the thing in the list shows
list item 1 : move
list item 2: move10
list item 3: move10steps

Last edited by -Pyumo- (Aug. 20, 2018 08:13:52)


The PyuShop

Members:
Pyumo
deck26
Scratcher
1000+ posts

Please Help ASAP!

-Pyumo- wrote:

-Pyumo- wrote:

heres what i coded:

when green flag clicked
ask [input] and wait
set [input v] to (answer)
set [index v] to [1]
set [new-word v] to []
repeat until <(index) > (length of (input))>
if <(letter (index) of (input)) = []> then
add [new-word] to [list v]
else
set [new-word v] to (join (new-word) (letter (index) of (input))
end
change [index v] by (1)
end
if <(length of (new-word)) > [0]> then
add (new-word) to [list v]
end

did i do it right?
also if so what do i do now?
if i didn't could you tell me how to fix it?

wait i did it wrong how do i fix cause if i put “move 10 steps” the thing in the list shows
list item 1 : move
list item 2: move10
list item 3: move10steps
You forgot to set new-word to blank after adding it to the list when you detect a space - so you just keep adding the words together. Otherwise you're there!
deck26
Scratcher
1000+ posts

Please Help ASAP!

Once it's working spend the time to actually understand how it works. It's not that difficult. If need be work through an example on paper.
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

deck26 wrote:

-Pyumo- wrote:

-Pyumo- wrote:

snip
You forgot to set new-word to blank after adding it to the list when you detect a space - so you just keep adding the words together. Otherwise you're there!
thanks so much!!!

deck26 wrote:

Once it's working spend the time to actually understand how it works. It's not that difficult. If need be work through an example on paper.
ok, sounds good!

Last edited by -Pyumo- (Aug. 20, 2018 09:15:32)


The PyuShop

Members:
Pyumo
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

so it work like index is the letter counter of the input, and new word is each word which finishes when the project detects a space in the input, and the list has separate items each being separate words! my one questions is, if i put a
if <(item (1 v) of [list v] :: list) = [move]> then

end

how will i do set ‘amount’ to item 2 if in coding on scratch those options are item ‘1’ item ‘last’ and item ‘random’

The PyuShop

Members:
Pyumo
deck26
Scratcher
1000+ posts

Please Help ASAP!

-Pyumo- wrote:

so it work like index is the letter counter of the input, and new word is each word which finishes when the project detects a space in the input, and the list has separate items each being separate words! my one questions is, if i put a
if <(item (1 v) of [list v] :: list) = [move]> then

end

how will i do set ‘amount’ to item 2 if in coding on scratch those options are item ‘1’ item ‘last’ and item ‘random’
You can put a variable in there or just a number.

(item (10 v) of [list v] :: list)
(item (myvalue) of [list v] :: list)
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

thanks! but… i need to code it more because the thing being moved is a separate sprite, and it doesn't only move! it also points in direction and puts pen up and down. heres what i have so far:

Sprite: Engine

when green flag clicked
ask [input] and wait
set [input v] to (answer)
set [index v] to [1]
set [new-word v] to []
repeat until <(index) > (length of (input))>
if <(letter (index) of (input)) = []> then
add [new-word] to [list v]
set [new word v] to []
else
set [new-word v] to (join (new-word) (letter (index) of (input))
end
change [index v] by (1)
end
if <(length of (new-word)) > [0]> then
add (new-word) to [list v]
set [new word v] to []
end
if <(item (1 v) of [list v] :: list) = [move]> then
set [code v] to (item (2 v) of [list v] :: list)
end
if <(item (1 v) of [list v] :: list) = [pen]> then
set [code v] to (item (2 v) of [list v] :: list)
end
if <<<(item (1 v) of [list v] :: list) = [point]> and <(item (2 v) of [list v] :: list) = [in]>> and <(item (3 v) of [list v] :: list) = [direction]>> then
set [code v] to (item (4 v) of [list v] :: list)
end
broadcast [message1 v]

Sprite: Turtle

when green flag clicked
go to x: (0) y: (0)
pen down
clear

when I receive [message1 v]

do you have any tips?

Last edited by -Pyumo- (Aug. 20, 2018 09:43:36)


The PyuShop

Members:
Pyumo
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

nevermind i did it!!! honestly, your good at teaching. you didn't give me a script to blindly follow, you made me figure it out. that made it so i could figure other stuff out easily too! thanks, your great!

The PyuShop

Members:
Pyumo
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

if you want, here's the link to the game you helped me with!

The PyuShop

Members:
Pyumo
deck26
Scratcher
1000+ posts

Please Help ASAP!

Glad you're making progress. You probably don't want to reset things at the start of your forever loop. Otherwise things like change direction end up being undone next time you broadcast. You might also try different broadcasts for the different commands.

In fact you can use a variable in the broadcast block.

broadcast (item (1 v) of [list v] :: list) 
would mean you would broadcast ‘pen’ or ‘point’ or ‘move’ according to the input. Just be careful though - Move as a broadcast won't work if you're only expecting move (the upper/lower case matters in that context). So you may prefer just to manually set your broadcasts so they match the input - Scratch will think Move=move so you can handle upper and lower case by saying

if <(variable) = [move]> then
broadcast [move v]
end
-Pyumo-
Scratcher
33 posts

Please Help ASAP!

ill see how i can fix it!

The PyuShop

Members:
Pyumo

Powered by DjangoBB