- Home /
Implicit downcast from 'Object' to 'String'.
Any idea beside #pragma downcast?
private var stateArray = new Array [3];
private var replyArray = new Array [3];
private var controlCenter : GameObject;
var state : int;
function Start () {
controlCenter = gameObject.Find("Control Center");
stateArray[0] = lookupState0;
stateArray[1] = lookupState1;
stateArray[2] = lookupState2;
replyArray[0] = repliesState0;
replyArray[1] = repliesState1;
replyArray[2] = repliesState2;
}
function LookUpState (object : GameObject, currentState: int, picker : String) {
var element : int = 0; // variable to track the element number for a match
if (picker == controlCenter.GetComponent(GameManager).defaultCursor.name ) var matchCursor = "default";
else matchCursor = picker;
for(var contents : String in stateArray[currentState]) { //***** error here - Implicit downcast from 'Object' to 'String'
var readString : String[] = contents.Split(",".Chars[0]);
if(readString[0] == matchCursor) {
var actionMsg : String = replyArray[currentState][element]; //***** error here - Implicit downcast from 'Object' to 'String'
controlCenter.GetComponent(GameManager).actionMsg= actionMsg;
TimeAdjuster(actionMsg);
var nextState : int = parseInt(readString [1]);
object.SendMessage("ProcessObject", nextState);
var tempLength = (readString.length);
if(tempLength > 2){
for (var x = 2; x < tempLength; x = x + 2) {
var tempS = readString[x];
if (tempS.Substring(0,1) == " ") tempS = tempS.Substring(1);
var auxObject = gameObject.Find(tempS);
var newState = parseInt(readString[x+1]);
auxObject.SendMessage( "ProcessObject",newState);
}
}
}
Comment
You need to post the full script. If this IS your full script, you have a ton of undefined variables. You also need to be WAY more SPECIFIC! Describe your issue, where the issue is in the code, why you want to change it.
Answer by Graham-Dunnett · Aug 16, 2013 at 02:34 PM
'stateArray' is un-typed, so Unity assumes it is an array of Objects. Your line 39 grabs one of the Objects and says it's a String, which the compiler correctly tells you is an implicit downcast. You probably want to use #pragma strict
(which all scripts have out of the box) to help remind you to type your objects correctly.
Your answer
