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

#1 2011-10-26 21:50:03

FarrelBuch
New Scratcher
Registered: 2011-10-26
Posts: 3

Drop down list, make a selection

I know how I can create a list of 4 objects (eg. "addition", "subtraction", "multiplication", "division"). How do I then select one of the items and feed that selection as the answer so that my if statements can proceed with the desired operation? Thanks a lot.

Offline

 

#2 2011-10-26 22:04:20

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Drop down list, make a selection

Put this in the addition sprite and similar code in the others (replace the word "addition" with the other operators).

<when[ addition ]clicked>
<set{ operator }to( addition )>

To do math:

<when I receive[  DoMath  ]>
<if><( <{  operator  }> <=>  addition  )>
      <set{  result  }to(  ((  <{  x  }>  <+>  <{  y  }>  ))
<else>
      <if>

etc. for all the operators


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2011-10-27 21:26:36

FarrelBuch
New Scratcher
Registered: 2011-10-26
Posts: 3

Re: Drop down list, make a selection

I could not find a way to do when "addition" clicked. I have posted a picture online for you to look at.

https://picasaweb.google.com/111947489942124903382/ScratchPorgraming#5668347145801730898

My script makes the list but relies and text input to proceed. How do I make it wait for me to select something from the list and how does it store what I selected? I would love your help. I can program in R but have just started Scratch.

Offline

 

#4 2011-10-28 09:49:39

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Drop down list, make a selection

There is a block under Control (third from the top) that activates the script under it when a sprite is clicked. I believe you are trying to replace your <ask ("what equation") and wait> block with buttons.

What I would do is make it so when the "addition" button is clicked, set a variable (called operator) to "addition" and compare that with the if statements.

Instead of

<if><( <answer> <=> addition )>
<say[ (( <{ first  }> <+> <{ second  }> )) ]>
<end>

use:


<if><( <{ operator  }> <=> addition )>
<say[ (( <{ first  }> <+> <{ second  }> )) ]>
<end>

Last edited by MoreGamesNow (2011-10-28 09:50:46)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2011-10-29 16:56:45

FarrelBuch
New Scratcher
Registered: 2011-10-26
Posts: 3

Re: Drop down list, make a selection

Thanks so much for your help but I am still stuck.

MoreGamesNow wrote:

make it so when the "addition" button is clicked, set a variable (called operator) to "addition"
>

That is the part I am having trouble with. I wish there was a control that said "when sprite1 operations, item 1 is clicked". Instead there is only "when sprite1 clicked". Does that mean that I need to have a separate sprite for each operation. In other words is it true to say that Scratch does not support selectable drop down lists?

Offline

 

#6 2011-10-29 20:04:49

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Drop down list, make a selection

Yes  hmm


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer