- Home /
Question by
SomeRandomGuy · Feb 14, 2014 at 03:04 PM ·
javascriptarraydatetimecustom class
DateTime, get all dates for the current week?
So, I've been trying to get all dates with DateTime using this script, but it throws a nullreference at line 17. Any idea why? I've only just now started looking at DateTime, so maybe I'm misunderstanding some stuff here.
Here's the script( called Test.js ) :
#pragma strict
import System;
import System.Globalization;
var testArr: testClass[];
function Start()
{
testArr = new testClass[7];
for(var i:int=0;i<7;i++)
{
var tmpWeekStart: DateTime = DateTime.Now;
tmpWeekStart.AddDays(-Convert.ToInt32(DateTime.Now.DayOfWeek));
testArr[i].testDate = tmpWeekStart.AddDays(i);
print(testArr[i].testDate);
}
}
function Update () {
}
class testClass
{
var testDate: DateTime;
}
Comment
Best Answer
Answer by whydoidoit · Feb 14, 2014 at 03:18 PM
You need to create an instance of your testClass - creating the array just allocates space for it
testArr[i] = new testClass();
Consider naming types with a capital first letter for convention.
Oh of course! That was stupid of me. Thanks for the help!
PS: the na$$anonymous$$g slipped my $$anonymous$$d there, I usually try doing that, but as this was a test script I got sloppy, haha!