can not change boolean value....(JavaScript)

Helo Unity3D guru :slight_smile: look, here is my code:

function Update() {
	movenpart2.transform.position = Dummy2.transform.position;
	movenpart.transform.position.x = Dummy1.transform.position.x;
	movenpart.transform.position.y = Dummy1.transform.position.y;
	movenpart.transform.position.z = Dummy2.transform.position.z;
	
	if(moveToFirst == true){
		var ss1 = Mathf.Abs(x[0]);
		var ss2 = Mathf.Abs(y[0]);
		var xx1 = Vector3(x[0],Dummy1.transform.position.y,Dummy1.transform.position.z); 
		var yy1 = Vector3(Dummy2.transform.position.x,Dummy2.transform.position.y,y[0]);
		var firstDist1 = Vector3.Distance(Dummy1.transform.position, xx1);
		var firstDist2 = Vector3.Distance(Dummy2.transform.position, yy1);
		Dummy1.transform.position = Vector3.Lerp (Dummy1.transform.position, xx1, ss1 * Regularspeed * Time.time / firstDist1);
		Dummy2.transform.position = Vector3.Lerp (Dummy2.transform.position, yy1, ss2 * Regularspeed * Time.time / firstDist2);	
	}
	
	
	
	if (Dummy1.transform.position == Vector3(Dummy1.transform.position.x,Dummy1.transform.position.y,x[0]) && Dummy2.transform.position == Vector3(y[0],Dummy2.transform.position.y,Dummy1.transform.position.z) && moveToFirst == true) {
	//if (firstDist1 == 0 && firstDist2 == 0) {
	    moveToFirst = false;
	    counter = 1;
	    startCuttin = true;
	}
	
	if(moveToFirst) print("moveToFirst");
	else print("moveToFirst False");
					
	 if(startCuttin) print("Cuttin");
	 else print("Cut False");
} ///End of update func.

If position of movenpart & movenpart2 variables == array x[0], y[0](used for Z coord.)I need turn to false variable moveToFirst and startCuttin to true

I see in SceneView that Coordinates equal to than what are in my arrays, but I see in console that values of moveToFirst and startCuttin doesn’t change… Can smbdy tell me what is wrong? Thanx for attention…
P.S. Sorry for my poor English if smthing wrong:)

Try to declare moveToFirst and startCuttin as static variable …

static var moveToFirst:boolean=true;
static var startCuttin:boolean=false; 

before your function

Code: Move.js

import System.IO;
private var coordinates : String = "xyz.txt";
var pointCount;
var xx : Vector3;
var yy : Vector3;
var dist : float;
var dist2 : float;
var t : float;

///////////////////////////////////////////////////

private var Regularspeed = 0.0025;
private var helper_var = 1;
var movenpart: Transform;
var movenpart2: Transform;
var Dummy1 : Transform;
var Dummy2 : Transform;
private var counter : int;

///////////////////////////////////////////////////

var x = new Array();
var y = new Array();
var sx = new Array();
var sy = new Array();
static var moveToFirst : boolean;
static var startCuttin : boolean;
static var finalstep : boolean;

///////////////////////////////////////////////////
///////////MY_FUCN
function MoveTo(thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float){
var i = 0.0;
var rate = 1.0/time;
	while(i<1.0){
		i += Time.deltaTime * rate;
		thisTransform.position = Vector3.Lerp(startPos, endPos, i);
		yield;
	}
}
///////////END_OF_MY_FUCN

function OnGUI () {
	if (GUI.Button(Rect(20, 25, 100, 30),"ReadFromFile")) {
		moveToFirst = false;
		startCuttin = false;
		finalstep = false;
		var sr = new StreamReader(Application.dataPath + "/" + coordinates);
		var fileContents = sr.ReadToEnd();
		sr.Close();
		var s:int;
		s=0;		
        var lines = fileContents.Split("

“[0]);
pointCount = int.Parse(lines[0]);
for(var i = 1; i < pointCount; i++){
if(i%2){
;
x = float.Parse(lines*);*
* y = float.Parse(lines[i+1]);
print(“i=” + i + " s=” + s + " x=" + x +" y=" + y~~);
s++;
}
}~~*

~~ }~~
~~ if (GUI.Button(Rect(20, 75, 100, 30),“TurnON”)) {~~
~~ moveToFirst = true;~~
~~ } ~~

~~ if (GUI.Button(Rect(20, 150, 100, 30),“TurnON2”)) {~~
~~ moveToFirst = false;~~
~~ startCuttin = true;~~
~~ counter = 1;~~
~~ }~~

}
function Update() {
~~ movenpart2.transform.position = Dummy2.transform.position;~~
~~ movenpart.transform.position.x = Dummy1.transform.position.x;~~
~~ movenpart.transform.position.y = Dummy1.transform.position.y;~~
~~ movenpart.transform.position.z = Dummy2.transform.position.z;~~

~~ //---------------------------------------------------------------------------------------~~
~~ if(moveToFirst == true){~~
~~ var ss1 = Mathf.Abs(x[0]);~~
~~ var ss2 = Mathf.Abs(y[0]);~~
~~ var xx1 = Vector3(x[0],Dummy1.transform.position.y,Dummy1.transform.position.z);~~
~~ var yy1 = Vector3(Dummy2.transform.position.x,Dummy2.transform.position.y,y[0]);~~
~~ var firstDist1 = Vector3.Distance(Dummy1.transform.position, xx1);~~
~~ var firstDist2 = Vector3.Distance(Dummy2.transform.position, yy1);~~
~~ Dummy1.transform.position = Vector3.Lerp (Dummy1.transform.position, xx1, ss1 * Regularspeed * Time.time / firstDist1);~~
~~ Dummy2.transform.position = Vector3.Lerp (Dummy2.transform.position, yy1, ss2 * Regularspeed * Time.time / firstDist2); ~~
~~ }~~

~~ if (Dummy1.transform.position == Vector3(Dummy1.transform.position.x,Dummy1.transform.position.y,x[0]) && Dummy2.transform.position == Vector3(y[0],Dummy2.transform.position.y,Dummy1.transform.position.z) && moveToFirst == true) {~~
~~ //if (firstDist1 == 0 && firstDist2 == 0) {~~
~~ moveToFirst = false;~~
~~ counter = 1;~~
~~ startCuttin = true;~~
~~ }~~

~~ if(moveToFirst){print(“moveToFirst”);}~~
~~ else print(“moveToFirst False”);~~

~~ if(startCuttin){print(“Cuttin”);}~~
~~ else print(“Cut False”);~~
~~ //////////////START - CUTTING~~
~~ if(startCuttin == true && counter < pointCount/2 ){~~
~~ var sss1 = Mathf.Abs(x[(counter-1)] - x[counter]);~~
~~ var sss2 = Mathf.Abs(y[(counter-1)] - y[counter]);~~
~~ var xxx1 = Vector3(x[counter],Dummy1.transform.position.y,Dummy1.transform.position.z);~~
~~ var yyy1 = Vector3(Dummy2.transform.position.x,Dummy2.transform.position.y,y[counter]);~~
~~ var fDist1 = Vector3.Distance(Dummy1.transform.position, xxx1);~~
~~ var fDist2 = Vector3.Distance(Dummy2.transform.position, yyy1);~~
~~ print(Dummy2.transform.position + " " + xxx1 + " " + yyy1 + " " +sss2 + " " + counter);~~
~~ Dummy1.transform.position = Vector3.Lerp (Dummy1.transform.position, xxx1, sss1 * Regularspeed * Time.time / fDist1);~~
~~ Dummy2.transform.position = Vector3.Lerp (Dummy2.transform.position, yyy1, sss2 * Regularspeed * Time.time / fDist2); ~~
~~ }~~

~~ //if (Dummy1.transform.position == Vector3(Dummy1.transform.position.x,Dummy1.transform.position.y,x[counter]) && Dummy2.transform.position == Vector3(y[counter],Dummy2.transform.position.y,Dummy1.transform.position.z)) {~~
~~ if (fDist1 == 0 && fDist2 == 0) {~~
~~ //moveToFirst = false;~~
~~ counter++;~~
~~ //startCuttin = true;~~
~~ }~~
}
ScreenShots:
1. [XYZ.TXT][1]

[Pressing buttons “ReadFormFile” and
“TurnON”][2]

[Show how it works][3]

[Console LOG][4]
~~[1]: ImageShack - Best place for all of your image hosting and image sharing needs
~~[2]: ImageShack - Best place for all of your image hosting and image sharing needs
~~[3]: ImageShack - Best place for all of your image hosting and image sharing needs
~~[4]: ImageShack - Best place for all of your image hosting and image sharing needs

doesn’t help…
have any other ideas?
P.S. what is the difference between static var , var , private var (and what type of variable there are?)

static var are global variables that can be used all over the function in a script if they are declared outside the functions, they can also be used by other scripts, they can be modified from outside the script in the properties panel … private var are all used in the script itself and cannot be modified from outside the scrip … that’s why you need to declare it static so that all modification to the variable value would be taken in consideration