Jump to content

  • Log In with Google      Sign In   
  • Create Account

Unity3d glitch?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 kryotech   Members   -  Reputation: 937

Like
-2Likes
Like

Posted 07 May 2012 - 08:10 PM

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!
Kryotech

Sponsor:

#2 fastcall22   Crossbones+   -  Reputation: 4463

Like
0Likes
Like

Posted 07 May 2012 - 10:05 PM


var a = 0;

if ( a = 1 )

    alert ( "It's because it should be 'a == 1'");


c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#3 AdrianC   Members   -  Reputation: 602

Like
0Likes
Like

Posted 07 May 2012 - 11:15 PM

Post your code, but no I'm pretty sure Unity can handle if statements just fine.

#4 kryotech   Members   -  Reputation: 937

Like
0Likes
Like

Posted 08 May 2012 - 04:55 AM

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, 08 May 2012 - 04:57 AM.

Kryotech

#5 VildNinja   Members   -  Reputation: 464

Like
0Likes
Like

Posted 08 May 2012 - 05:15 AM

Could you provide context for the code?

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

#6 kryotech   Members   -  Reputation: 937

Like
0Likes
Like

Posted 08 May 2012 - 04:36 PM

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, 08 May 2012 - 04:44 PM.

Kryotech

#7 VildNinja   Members   -  Reputation: 464

Like
0Likes
Like

Posted 09 May 2012 - 07:44 AM

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.

#8 Sandman   Moderators   -  Reputation: 2136

Like
0Likes
Like

Posted 10 May 2012 - 02:45 AM

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, 10 May 2012 - 02:45 AM.


#9 kryotech   Members   -  Reputation: 937

Like
0Likes
Like

Posted 10 May 2012 - 04:56 AM

Ok, so I think I found the problem, it was the array assignment that was off. Thanks for the help!
Kryotech




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS