This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-04-05 17:12:27

usuariointeresado
New Scratcher
Registered: 2012-04-05
Posts: 2

What's up about various answers to diferent questions in scratch?

Sorry for my english. I'm trying to make a program that ask various questions and then add the numeric result... When I try it the only answer I can operate with is the last. Help please.

Offline

 

#2 2012-04-05 21:21:26

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: What's up about various answers to diferent questions in scratch?

Hmm... I see what you mean. Perhaps try something like this.

when gf clicked
ask [first number] and wait
set [#1 v] to (answer)
ask [second number] and wait
set [#2 v] to (answer)
ask [third number] and wait
set [#3 v] to (answer)
set [total v] to ( (#1) + ( (#2) + (#3) ) )
say (join [The total is ] (total) )
If you a lot of numbers, you could use lists, but it would be more complicated.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#3 2012-04-05 21:32:56

Mokat
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: What's up about various answers to diferent questions in scratch?

Lucario621 wrote:

Hmm... I see what you mean. Perhaps try something like this.

when gf clicked
ask [first number] and wait
set [#1 v] to (answer)
ask [second number] and wait
set [#2 v] to (answer)
ask [third number] and wait
set [#3 v] to (answer)
set [total v] to ( (#1) + ( (#2) + (#3) ) )
say (join [The total is ] (total) )
If you a lot of numbers, you could use lists, but it would be more complicated.

This seems like it's the simplest way.


http://www.eggcave.com/egg/977371.pnghttp://www.eggcave.com/egg/977376.pnghttp://www.eggcave.com/egg/1005291.pnghttp://www.eggcave.com/egg/996745.png

Offline

 

#4 2012-04-05 22:11:31

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: What's up about various answers to diferent questions in scratch?

The way with lists (unlimited amount of inputs)

when gf clicked
ask [how many numbers?] and wait
set [numbers v] to <answer>
set [1 v] to [0]
repeat (numbers)
change [1 v] by [1]
ask <join<join [what is number] <1>>[ ?]> and wait
add <answer> to [list of numbers v]
end
repeat (length of numbers)
replace item (1 v) of [list of numbers v] with <<item (1 v) of [list of numbers v]>+<item (2 v) of [list of numbers v]>>
end
say <join <item (1 v) of [list of numbers v]> [ is the total]>

Offline

 

Board footer