Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with farm eating script
- ravinto
- Scratcher
20 posts
Help with farm eating script
Hi
I have tried whole hours and days to make script but it doesnt work. Its about if you press “space” then the wheat will decrease with (wheat amount -1 each 10 seconds) . It does work with wheat-1 each 10 seconds but when i press “space” again it seems that nothing changes. It just continues with wheat amount-1 and not wheat amount-2 and ect…
It is about variabels.
I am thankful for help.
I have tried whole hours and days to make script but it doesnt work. Its about if you press “space” then the wheat will decrease with (wheat amount -1 each 10 seconds) . It does work with wheat-1 each 10 seconds but when i press “space” again it seems that nothing changes. It just continues with wheat amount-1 and not wheat amount-2 and ect…
It is about variabels.
I am thankful for help.
Last edited by ravinto (July 20, 2013 19:15:16)
- drmcw
- Scratcher
1000+ posts
Help with farm eating script
when gf clicked
set wheat to 100
set multiplier to 0
forever
wait 10 seconds
change wheat by multiplier * -1
when space key pressed
change multiplier by 1
wheat and multiplier are both variables.
set wheat to 100
set multiplier to 0
forever
wait 10 seconds
change wheat by multiplier * -1
when space key pressed
change multiplier by 1
wheat and multiplier are both variables.
Last edited by drmcw (July 20, 2013 20:16:32)
- PERCE-NEIGE
- Scratcher
100+ posts
Help with farm eating script
Can you give me a link toward your project. I'll test.
- PERCE-NEIGE
- Scratcher
100+ posts
Help with farm eating script
I see. Your project is not shared yet. You can share it for a while saying “work in progress” if you want.
I tried:
When Green_Flag is clicked.
Set “wheat” to 100 # reinitialize “wheat”
Set “multiplier” to 0 # reinitialize “multiplier”
forever
Wait 10 seconds
Change wheat by multiplier * -1 #decrease wheat every 10 seconds
# for now, multiplier is 0, so wheat + (0 X -1) = wheat
When space pressed
Change multiplier by 1
It works, but you need, in my opinion to send a message after pressing the space key, to tell the wheat variable to change by something outside of the loop. I would write, with 3 scripts:
1/ When space pressed
Change multiplier by 1
Send message “now change”
2/ When I received “now change”
Wait 10 sec
Change wheat by multiplier * -1
3/ When Green_flag clicked
Set wheat to 100
Set multiplier to 0
Forever
Send “now change”
I don't know if it is the behaviour you were expecting.
You can try changing the place of “wait 10 sec”, inside the broadcasting message, or before the broadcasting,
I didn't test what is the best option.
I tried:
When Green_Flag is clicked.
Set “wheat” to 100 # reinitialize “wheat”
Set “multiplier” to 0 # reinitialize “multiplier”
forever
Wait 10 seconds
Change wheat by multiplier * -1 #decrease wheat every 10 seconds
# for now, multiplier is 0, so wheat + (0 X -1) = wheat
When space pressed
Change multiplier by 1
It works, but you need, in my opinion to send a message after pressing the space key, to tell the wheat variable to change by something outside of the loop. I would write, with 3 scripts:
1/ When space pressed
Change multiplier by 1
Send message “now change”
2/ When I received “now change”
Wait 10 sec
Change wheat by multiplier * -1
3/ When Green_flag clicked
Set wheat to 100
Set multiplier to 0
Forever
Send “now change”
I don't know if it is the behaviour you were expecting.
You can try changing the place of “wait 10 sec”, inside the broadcasting message, or before the broadcasting,
I didn't test what is the best option.
Last edited by PERCE-NEIGE (July 20, 2013 20:50:41)
- ravinto
- Scratcher
20 posts
Help with farm eating script
when gf clicked
set wheat to 100
set multiplier to 0
forever
wait 10 seconds
change wheat by multiplier * -1
when space key pressed
change multiplier by 1
wheat and multiplier are both variables.
I have tried but doesnt work. It must be wrong how i did put it. http://scratch.mit.edu/projects/11516329/#editor
I see. Your project is not shared yet. You can share it for a while saying “work in progress” if you want.
I tried:
When Green_Flag is clicked.
Set “wheat” to 100 # reinitialize “wheat”
Set “multiplier” to 0 # reinitialize “multiplier”
forever
Wait 10 seconds
Change wheat by multiplier * -1 #decrease wheat every 10 seconds
# for now, multiplier is 0, so wheat + (0 X -1) = wheat
When space pressed
Change multiplier by 1
It works, but you need, in my opinion to send a message after pressing the space key, to tell the wheat variable to change by something outside of the loop. I would write, with 3 scripts:
1/ When space pressed
Change multiplier by 1
Send message “now change”
2/ When I received “now change”
Wait 10 sec
Change wheat by multiplier * -1
3/ When Green_flag clicked
Set wheat to 100
Set multiplier to 0
Forever
Send “now change”
I don't know if it is the behaviour you were expecting.
You can try changing the place of “wait 10 sec”, inside the broadcasting message, or before the broadcasting,
I didn't test what is the best option.
I am bit new to understand written script, so maybe its because it didnt work.
I followed the first script, but didnt work. http://scratch.mit.edu/projects/11516329/#editor
The second didnt work for me too, but its seems more that i didnt understand. http://scratch.mit.edu/projects/11518781/#editor
You mayble pls look at it if i have put it right.
- PERCE-NEIGE
- Scratcher
100+ posts
Help with farm eating script
You don't have to undestand the written script, you just open a blank project, and paste the script as you read their descriptions.
When green_flag clicked —-> you put the green flag block in your new project.
Set Wheat to —> you put this block too.
Etc…
When green_flag clicked —-> you put the green flag block in your new project.
Set Wheat to —> you put this block too.
Etc…
- Discussion Forums
- » Help with Scripts
- » Help with farm eating script