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

#26 2010-01-15 11:34:24

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Time/Date

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

 

#27 2010-01-24 13:20:13

SUPERawesomeCOOL
Scratcher
Registered: 2009-12-19
Posts: 8

Re: Time/Date

getTime and getDate
at least in TI-BASIC

Offline

 

#28 2010-01-24 14:14:52

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Time/Date

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].
    ^ 0

After 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!


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#29 2010-02-17 17:12:46

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Time/Date

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].
    ^ 0

After 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!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#30 2010-02-28 08:49:35

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Offline

 

#31 2010-03-10 21:12:33

Zorbak42
Scratcher
Registered: 2009-01-27
Posts: 100+

Re: Time/Date

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].
    ^ 0

After 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

 

#32 2010-03-12 01:45:27

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Time/Date

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].
    ^ 0

After 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.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#33 2010-03-12 21:39:21

Zorbak42
Scratcher
Registered: 2009-01-27
Posts: 100+

Re: Time/Date

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.  smile

Last edited by Zorbak42 (2010-03-15 10:55:06)

Offline

 

#34 2010-03-19 07:37:23

Zorbak42
Scratcher
Registered: 2009-01-27
Posts: 100+

Re: Time/Date

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

 

Board footer