From 64fb52699c619d772dc1ff021b71ebf0546e40ec Mon Sep 17 00:00:00 2001 From: Scimonster Date: Wed, 30 Oct 2013 12:34:18 +0200 Subject: [PATCH] Add timeAndDate block. --- js/primitives/SensingPrims.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/js/primitives/SensingPrims.js b/js/primitives/SensingPrims.js index 0529081..6ae31d5 100644 --- a/js/primitives/SensingPrims.js +++ b/js/primitives/SensingPrims.js @@ -29,6 +29,8 @@ SensingPrims.prototype.addPrimsTo = function(primTable) { primTable['distanceTo:'] = this.primDistanceTo; primTable['getAttribute:of:'] = this.primGetAttribute; + + primTable['timeAndDate'] = this.primTimeDate; } SensingPrims.prototype.primTouching = function(b) { @@ -206,6 +208,19 @@ SensingPrims.prototype.primGetAttribute = function(b) { return 0; } +SensingPrims.prototype.primTimeDate = function(b) { + var dt = interp.arg(b, 0); + var now = new Date(); + if (dt == 'year') return now.getFullYear(); + if (dt == 'month') return now.getMonth()+1; + if (dt == 'date') return now.getDate(); + if (dt == 'day of week') return now.getDay()+1; + if (dt == 'hour') return now.getHours(); + if (dt == 'minute') return now.getMinutes(); + if (dt == 'second') return now.getSeconds(); + return 0; +} + // Helpers SensingPrims.prototype.mouseOrSpritePosition = function(arg) { if (arg == "_mouse_") {