songhead95 wrote:
rdococ wrote:
Where is Scratch 1.5?
oh dear I think you are lost
No I am not, but I want Scratch 2.0!
(My mistake on 'Where is Scratch 1.5?'. It's 2.0, not 1.5!)
Offline
getTime and getDate
at least in TI-BASIC
Offline
Here's the code I used to get a time/date block into streak:
First, add this to scratchSpriteMorph class:
('date/time:%t' #r #returnW:)Under scratch-blocks > commandBlockMorph > private > uncoloredArgMorphFor:, add:
$t = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #timeDates;
choice: 'time'].Under scriptableScratchMorph > sensing ops, add this:
timeDates
^ #('time' 'hour' 'minute' 'second' 'date' 'day of month' 'day of year' 'weekday-name' 'weekday-#' 'month-name' 'month-#' 'year' )Finally, under scriptableScratchMorph > sensing ops add this function:
returnW: t1
| time date |
time _ Time now.
date _ Date today.
'time' = t1 ifTrue: [^ time].
'hour' = t1 ifTrue: [^ time hours].
'minute' = t1 ifTrue: [^ time minutes].
'second' = t1 ifTrue: [^ time seconds].
'date' = t1 ifTrue: [^ date].
'weekday-name' = t1 ifTrue: [^ date weekday].
'weekday-#' = t1
ifTrue:
[date weekday = 'Monday' ifTrue: [^ 1].
date weekday = 'Tuesday' ifTrue: [^ 2].
date weekday = 'Wednesday' ifTrue: [^ 3].
date weekday = 'Thursday' ifTrue: [^ 4].
date weekday = 'Friday' ifTrue: [^ 5].
date weekday = 'Saturday' ifTrue: [^ 6].
date weekday = 'Sunday' ifTrue: [^ 7]].
'month-name' = t1 ifTrue: [^ date monthName].
'month-#' = t1 ifTrue: [^ date monthIndex].
'day of month' = t1 ifTrue: [^ date dayOfMonth].
'day of year' = t1 ifTrue: [^ date daysInYear - date daysLeftInYear].
'year' = t1 ifTrue: [^ date year].
^ 0After all of this, you should have a shiny new date/time block!
Just be glad that I made the code; you just have to copy it!
Offline
billyedward wrote:
Here's the code I used to get a time/date block into streak:
First, add this to scratchSpriteMorph class:Code:
('date/time:%t' #r #returnW:)Under scratch-blocks > commandBlockMorph > private > uncoloredArgMorphFor:, add:
Code:
$t = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #timeDates; choice: 'time'].Under scriptableScratchMorph > sensing ops, add this:
Code:
timeDates ^ #('time' 'hour' 'minute' 'second' 'date' 'day of month' 'day of year' 'weekday-name' 'weekday-#' 'month-name' 'month-#' 'year' )Finally, under scriptableScratchMorph > sensing ops add this function:
Code:
returnW: t1 | time date | time _ Time now. date _ Date today. 'time' = t1 ifTrue: [^ time]. 'hour' = t1 ifTrue: [^ time hours]. 'minute' = t1 ifTrue: [^ time minutes]. 'second' = t1 ifTrue: [^ time seconds]. 'date' = t1 ifTrue: [^ date]. 'weekday-name' = t1 ifTrue: [^ date weekday]. 'weekday-#' = t1 ifTrue: [date weekday = 'Monday' ifTrue: [^ 1]. date weekday = 'Tuesday' ifTrue: [^ 2]. date weekday = 'Wednesday' ifTrue: [^ 3]. date weekday = 'Thursday' ifTrue: [^ 4]. date weekday = 'Friday' ifTrue: [^ 5]. date weekday = 'Saturday' ifTrue: [^ 6]. date weekday = 'Sunday' ifTrue: [^ 7]]. 'month-name' = t1 ifTrue: [^ date monthName]. 'month-#' = t1 ifTrue: [^ date monthIndex]. 'day of month' = t1 ifTrue: [^ date dayOfMonth]. 'day of year' = t1 ifTrue: [^ date daysInYear - date daysLeftInYear]. 'year' = t1 ifTrue: [^ date year]. ^ 0After all of this, you should have a shiny new date/time block!
Just be glad that I made the code; you just have to copy it!
Thank you SOOO much BG! You have been an amazing help! I can't wait to use this block for all kinds of things!
Offline
ThePCKid wrote:
3 = 3 #ifTrue [self inform 'Good job!'] #ifElse [self inform 'Not correct]
Nice try at some Squeak code.
Offline
billyedward wrote:
Here's the code I used to get a time/date block into streak:
First, add this to scratchSpriteMorph class:Code:
('date/time:%t' #r #returnW:)Under scratch-blocks > commandBlockMorph > private > uncoloredArgMorphFor:, add:
Code:
$t = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #timeDates; choice: 'time'].Under scriptableScratchMorph > sensing ops, add this:
Code:
timeDates ^ #('time' 'hour' 'minute' 'second' 'date' 'day of month' 'day of year' 'weekday-name' 'weekday-#' 'month-name' 'month-#' 'year' )Finally, under scriptableScratchMorph > sensing ops add this function:
Code:
returnW: t1 | time date | time _ Time now. date _ Date today. 'time' = t1 ifTrue: [^ time]. 'hour' = t1 ifTrue: [^ time hours]. 'minute' = t1 ifTrue: [^ time minutes]. 'second' = t1 ifTrue: [^ time seconds]. 'date' = t1 ifTrue: [^ date]. 'weekday-name' = t1 ifTrue: [^ date weekday]. 'weekday-#' = t1 ifTrue: [date weekday = 'Monday' ifTrue: [^ 1]. date weekday = 'Tuesday' ifTrue: [^ 2]. date weekday = 'Wednesday' ifTrue: [^ 3]. date weekday = 'Thursday' ifTrue: [^ 4]. date weekday = 'Friday' ifTrue: [^ 5]. date weekday = 'Saturday' ifTrue: [^ 6]. date weekday = 'Sunday' ifTrue: [^ 7]]. 'month-name' = t1 ifTrue: [^ date monthName]. 'month-#' = t1 ifTrue: [^ date monthIndex]. 'day of month' = t1 ifTrue: [^ date dayOfMonth]. 'day of year' = t1 ifTrue: [^ date daysInYear - date daysLeftInYear]. 'year' = t1 ifTrue: [^ date year]. ^ 0After all of this, you should have a shiny new date/time block!
Just be glad that I made the code; you just have to copy it!
The time/date thing sounds really awesome! But... I can't figure out where to put the "timeDates
^ #('time' 'hour' 'minute' 'second' 'date' 'day of month' 'day of year' 'weekday-name' 'weekday-#' 'month-name' 'month-#' 'year' )". When I put it right into Scratch-Objects>ScriptableScratchMorph>class>sensing ops and try to accept, a whole bunch of errors pop up about unknown variables or something. Please help me!
Offline
Zorbak42 wrote:
billyedward wrote:
Here's the code I used to get a time/date block into streak:
First, add this to scratchSpriteMorph class:Code:
('date/time:%t' #r #returnW:)Under scratch-blocks > commandBlockMorph > private > uncoloredArgMorphFor:, add:
Code:
$t = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #timeDates; choice: 'time'].Under scriptableScratchMorph > sensing ops, add this:
Code:
timeDates ^ #('time' 'hour' 'minute' 'second' 'date' 'day of month' 'day of year' 'weekday-name' 'weekday-#' 'month-name' 'month-#' 'year' )Finally, under scriptableScratchMorph > sensing ops add this function:
Code:
returnW: t1 | time date | time _ Time now. date _ Date today. 'time' = t1 ifTrue: [^ time]. 'hour' = t1 ifTrue: [^ time hours]. 'minute' = t1 ifTrue: [^ time minutes]. 'second' = t1 ifTrue: [^ time seconds]. 'date' = t1 ifTrue: [^ date]. 'weekday-name' = t1 ifTrue: [^ date weekday]. 'weekday-#' = t1 ifTrue: [date weekday = 'Monday' ifTrue: [^ 1]. date weekday = 'Tuesday' ifTrue: [^ 2]. date weekday = 'Wednesday' ifTrue: [^ 3]. date weekday = 'Thursday' ifTrue: [^ 4]. date weekday = 'Friday' ifTrue: [^ 5]. date weekday = 'Saturday' ifTrue: [^ 6]. date weekday = 'Sunday' ifTrue: [^ 7]]. 'month-name' = t1 ifTrue: [^ date monthName]. 'month-#' = t1 ifTrue: [^ date monthIndex]. 'day of month' = t1 ifTrue: [^ date dayOfMonth]. 'day of year' = t1 ifTrue: [^ date daysInYear - date daysLeftInYear]. 'year' = t1 ifTrue: [^ date year]. ^ 0After all of this, you should have a shiny new date/time block!
Just be glad that I made the code; you just have to copy it!The time/date thing sounds really awesome! But... I can't figure out where to put the "timeDates
^ #('time' 'hour' 'minute' 'second' 'date' 'day of month' 'day of year' 'weekday-name' 'weekday-#' 'month-name' 'month-#' 'year' )". When I put it right into Scratch-Objects>ScriptableScratchMorph>class>sensing ops and try to accept, a whole bunch of errors pop up about unknown variables or something. Please help me!
These are not errors, just warnings.
As long as you copy it verbatim, just 'confirm' when it asks 'please confirm, correct, or cancel.' If it says unknown variable, tell it to declare local.
Offline
When it says unknown variable, declare local isn't an option. It asks me to choose declare temp, self or cancel. After that warning, it the choices are selector, names, nameExists, and some other name stuff, cancel, and try harder. Then, another unknown variable asking declare temp or tempoBPM or cancel. Then selector again, names, nameExists, so on so on, try harder. Then, declare temp, sceneStates, submorphs, cancel. It just keeps going with stuff like that. And what is verbatim? Thanks.
Last edited by Zorbak42 (2010-03-15 10:55:06)
Offline
Never mind. I got it. I was adding the
"timeDates
^ #('time' 'hour' 'minute' 'second' 'date' 'day of month' 'day of year' 'weekday-name' 'weekday-#' 'month-name' 'month-#' 'year' )" to the sensing ops instead of replacing it to make a new whatchamicalit. Thanks, it's a cool block!
Offline