Unity3d glitch?
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!
This is the code that has issues:
The program always executes the first statement in the if, but executes the second statement when its supposed to.
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.
Could you provide context for the code?
Also have you tried adding a print(winningResponse); before and after the if statement?
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?
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?
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement