Unity3d glitch?

Started by
7 comments, last by warhound 11 years, 11 months ago
So I've been writing a program in Unity3d in JavaScript, and for some reason, on one particular if statement, it executes some of the code, despite the fact that it should not execute that code. I have tried to look for every possible reason that could cause this, but I know for certain that nothing in the program is causing certain statements to change. Is it possible that Unity3d has some internal error? If so, can it be corrected? Thanks for any help!

No one expects the Spanish Inquisition!

Advertisement

var a = 0;
if ( a = 1 )
alert ( "It's because it should be 'a == 1'");
Post your code, but no I'm pretty sure Unity can handle if statements just fine.
This is the code that has issues:



if (responses[theBest]>winningResponse){
winningInputWeights1=inputWeightSet1[theBest].weights;
winningResponse=responses[theBest];
}



The program always executes the first statement in the if, but executes the second statement when its supposed to.

No one expects the Spanish Inquisition!

Could you provide context for the code?

Also have you tried adding a print(winningResponse); before and after the if statement?
The code above is used to update an array (the winning input weights) after the best set of weights for a neural net have been found. After the winning weights have been updated, 3 more random weight sets are created with the winning weights as a starting point. I have monitored how many times the if statement has been executed, and done a print(winningResponse) type thing in Unity3d to see what is changing and what is not. The winningResponse only changed when the if statement is called. The winningWeights, however, change regardless, which should not happen.

EDIT:
Could it be that the fact that I'm trying to set an entire array equal to another array is messing with the program?

No one expects the Spanish Inquisition!

I doubt that the error is in the code piece above. Could you provide the code for the entire function? with types on all the variables please.

If you are using == between two arrays, it'll compare by reference. If you want to see if the elements in the arrays are equal you need to compare them one at a time.

If you are using == between two arrays, it'll compare by reference. If you want to see if the elements in the arrays are equal you need to compare them one at a time.


On a similar note, if you are using = (assignment) you are assigning a reference, not a creating a copy.

So doing LeftArray = RightArray does not copy the contents of RightArray to LeftArray, it simply makes them both point at the same thing, so you will not be able to change their elements independently.
Ok, so I think I found the problem, it was the array assignment that was off. Thanks for the help!

No one expects the Spanish Inquisition!

This topic is closed to new replies.

Advertisement