- Home /
NullReferenceException when trying to link 2 scripts
This is probably a newb question, but what I'm trying to do is create a function in one script, in this case 'Designer.js':
#pragma strict
// Initialize map.
function Initialize (Width:int, Height:int, defChar:String) {
var W: int = Width;
var H: int = Height;
var map = new String[W, H];
for (var x = 0; x < W; x++) {
for (var y = 0; y < H; y++) {
map[x, y] = defChar;
}
}
return map;
}
Then having another script call it, in this case 'NewlineTest.js':
#pragma strict
var mapTester: String[,];
function Start () {
var designerTestInst: Designer;
mapTester = designerTestInst.Initialize (10, 40, '#');
}
Both scripts are tacked onto a player character right now, and whenever I try to test this, it throws 'NullReferenceException: Object reference not set to an instance of an object'.
How do I fix this, and more importantly, what am I doing wrong here?
Answer by ExplodingCookie · Jul 22, 2013 at 09:04 PM
you have not passed in a reference to the Designer component. Replace line 5 with
var designerTestInst : Designer = gameObject.GetComponent(Designer);
This should solve your issue.
~ExplodingCookie
Your answer

Follow this Question
Related Questions
Problem calling functions from another script of the same gameObject 1 Answer
How do i change this numbers color for GUI.Label? 1 Answer
Ambiguous reference error with JS 1 Answer
Problem accessing script 2 Answers
Script issues [js] 0 Answers