Jump to content
  • Advertisement
Sign in to follow this  
deltaKshatriya

Unity Unity3d glitch?

This topic is 2261 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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. Edited by kryotech

Share this post


Link to post
Share on other sites
Could you provide context for the code?

Also have you tried adding a print(winningResponse); before and after the if statement?

Share this post


Link to post
Share on other sites
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? Edited by kryotech

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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. Edited by Sandman

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!