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

#1 2012-03-15 18:03:49

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

How do I make 2 answers seperate from one answer?

I'm trying to make a digital clock but I need help. An ask block will say, "What is the time?" I say, "2;40" The problem is, I need to be able to seperate this answer into two variables called Hours and Minutes. Is there anyone who can help me? No, I don't want it to say, "What hour is it?" and then say, "What minute is it?".

Last edited by coolhogs (2012-03-15 18:06:30)


Get ready for domination of:  tongue

Offline

 

#2 2012-03-15 18:07:08

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

You need to do string manipulation. I'm writing a script for you.

set [number v] to [1]
set [onhour v] to [1]

set [hour v] to []
set [minute v] to []

repeat (length of (answer))
if <(letter (number) of (answer)) = [:]>
set [onhour v] to [0] 
else
if <(onhour) = [1]>
set [hour v] to (join (hour) (letter (number) of (answer)))
else
set [minute v] to (join (minute) (letter (number) of (answer)))
end
end
change [number v] by [1]
end



Last edited by bobbybee (2012-03-15 18:11:26)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#3 2012-03-15 18:07:17

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: How do I make 2 answers seperate from one answer?

Hmm... Tricky... Couldn't you just use 1 variable?

Offline

 

#4 2012-03-15 18:18:01

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

turkey3 wrote:

Hmm... Tricky... Couldn't you just use 1 variable?

How would i do this symbol : for each number? Oh, bobbybee can you explain the script?


Get ready for domination of:  tongue

Offline

 

#5 2012-03-15 18:19:56

joletole
Scratcher
Registered: 2011-02-20
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

Well you could ask something like this,

What is the hour:

Then you could ask this,

What is the minute:

But then you would have to make something like this:

if <(answer)=[1]>
  set (minute) to [1]
end
if <(answer)=[1]>
  set (hour) to [1]
end
if <(answer)=[2]>
  set (minute) to [2]
end
if <(answer)=[2]>
  set (hour) to [2]
end
And you would have to do that for each one until 60.

Last edited by joletole (2012-03-15 18:20:20)

Offline

 

#6 2012-03-15 18:24:46

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

coolhogs wrote:

turkey3 wrote:

Hmm... Tricky... Couldn't you just use 1 variable?

How would i do this symbol : for each number? Oh, bobbybee can you explain the script?

I'll try my best. (for now, just put it right after the ask block)

1) Gets the variables set up:
-number is how many characters in of the answer have been looked at
-onhour says whether it is reading the hour or minute (based on where the colon is)
-hour and minute is the hour and minutes respectively

2) Runs a routine for each character (number/colon) of the string:
-Checks if it reached the colon. If it did, change to minutes rather than hours
-If it didn't, check whether it is on hours or minutes. Use the appropriate variable

-It sets the variable (hour or minute) to the current variable joined with the current character.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#7 2012-03-15 19:15:36

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

bobbybee wrote:

coolhogs wrote:

turkey3 wrote:

Hmm... Tricky... Couldn't you just use 1 variable?

How would i do this symbol : for each number? Oh, bobbybee can you explain the script?

I'll try my best. (for now, just put it right after the ask block)

1) Gets the variables set up:
-number is how many characters in of the answer have been looked at
-onhour says whether it is reading the hour or minute (based on where the colon is)
-hour and minute is the hour and minutes respectively

2) Runs a routine for each character (number/colon) of the string:
-Checks if it reached the colon. If it did, change to minutes rather than hours
-If it didn't, check whether it is on hours or minutes. Use the appropriate variable

-It sets the variable (hour or minute) to the current variable joined with the current  character.

smile  Thanks! Oh, can you make the script so that it deletes the zero and adds the : ?

Last edited by coolhogs (2012-03-15 19:17:42)


Get ready for domination of:  tongue

Offline

 

#8 2012-03-15 19:19:17

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: How do I make 2 answers seperate from one answer?

joletole wrote:

Well you could ask something like this,

What is the hour:

Then you could ask this,

What is the minute:

But then you would have to make something like this:

if <(answer)=[1]>
  set (minute) to [1]
end
if <(answer)=[1]>
  set (hour) to [1]
end
if <(answer)=[2]>
  set (minute) to [2]
end
if <(answer)=[2]>
  set (hour) to [2]
end
And you would have to do that for each one until 60.

It would actually be more like this

if <(answer)=[2]>
  set (hour) to (answer)

Offline

 

#9 2012-03-15 19:58:41

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

coolhogs wrote:

bobbybee wrote:

coolhogs wrote:


How would i do this symbol : for each number? Oh, bobbybee can you explain the script?

I'll try my best. (for now, just put it right after the ask block)

1) Gets the variables set up:
-number is how many characters in of the answer have been looked at
-onhour says whether it is reading the hour or minute (based on where the colon is)
-hour and minute is the hour and minutes respectively

2) Runs a routine for each character (number/colon) of the string:
-Checks if it reached the colon. If it did, change to minutes rather than hours
-If it didn't, check whether it is on hours or minutes. Use the appropriate variable

-It sets the variable (hour or minute) to the current variable joined with the current  character.

smile  Thanks! Oh, can you make the script so that it deletes the zero and adds the : ?

I don't really understand. Deleting the zero just requires another if statement, but what do you mean by adding the colon? Use the join block, I suppose.

join (join (hour) [:]) (minutes)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#10 2012-03-15 20:12:15

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

bobbybee wrote:

coolhogs wrote:

bobbybee wrote:


I'll try my best. (for now, just put it right after the ask block)

1) Gets the variables set up:
-number is how many characters in of the answer have been looked at
-onhour says whether it is reading the hour or minute (based on where the colon is)
-hour and minute is the hour and minutes respectively

2) Runs a routine for each character (number/colon) of the string:
-Checks if it reached the colon. If it did, change to minutes rather than hours
-If it didn't, check whether it is on hours or minutes. Use the appropriate variable

-It sets the variable (hour or minute) to the current variable joined with the current  character.

smile  Thanks! Oh, can you make the script so that it deletes the zero and adds the : ?

I don't really understand. Deleting the zero just requires another if statement, but what do you mean by adding the colon? Use the join block, I suppose.

join (join (hour) [:]) (minutes)

It puts the hours and the minutes together into the hour variable...


Get ready for domination of:  tongue

Offline

 

#11 2012-03-16 15:56:10

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

What do you want it to do?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#12 2012-03-16 19:14:49

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

Nevermind, I thInk I have it... Mods close it...


Get ready for domination of:  tongue

Offline

 

#13 2012-03-16 19:16:38

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

Just wondering, did my answer help?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#14 2012-03-16 19:22:59

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

A little... Mods don't close it... I just need hours to be seperate from minutes... The time is in the variable hours

Last edited by coolhogs (2012-03-16 19:25:29)


Get ready for domination of:  tongue

Offline

 

#15 2012-03-16 19:26:56

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

They are--hours is the hours, minutes is the minutes, the colon will be lost forever.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#16 2012-03-17 16:12:54

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

Hmm, no, it puts the variable hours and the variable minutes together in the variable hours.


Get ready for domination of:  tongue

Offline

 

#17 2012-03-17 19:04:29

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

Bump!


Get ready for domination of:  tongue

Offline

 

#18 2012-03-19 18:29:29

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How do I make 2 answers seperate from one answer?

Bump!


Get ready for domination of:  tongue

Offline

 

Board footer