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)
Offline
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)
Offline
Hmm... Tricky... Couldn't you just use 1 variable?
Offline
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] endAnd you would have to do that for each one until 60.
Last edited by joletole (2012-03-15 18:20:20)
Offline
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.
Offline
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.
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)
Offline
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] endif <(answer)=[1]> set (hour) to [1] endif <(answer)=[2]> set (minute) to [2] endif <(answer)=[2]> set (hour) to [2] endAnd 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
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.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)
Offline
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.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...
Offline
What do you want it to do?
Offline
Just wondering, did my answer help?
Offline
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)
Offline
They are--hours is the hours, minutes is the minutes, the colon will be lost forever.
Offline