- Home /
toggleing true / false
For some strange reason i can't use the true and false statement in my Javascript.
True and false won't turn color as if it was a code function. As solution i use a 0 and 1 but wan't the true and false function back.
Is there a solution to this problem? I can't find one on the forum here.
Don't get errors.
this is the script
//moving around var speed = 3.0; var rotateSpeed = 3.0;
// shooting var bullitPrefab: Transform;
//dying private var dead = 0;
//getting hit var tumbleSpeed = 800; var decreaseTime = 0.01; var decayTime = 0.01; static var gotHit = 0; private var backup = [tumbleSpeed, decreaseTime, decayTime];
function OnControllerColliderHit (hit : ControllerColliderHit) { if(hit.gameObject.tag == "fallout") {
dead = 1; //substract life here HealthControl.LIVES -= 1; }
if (hit.gameObject.tag == "enemyProjectile")
{
gotHit = 1;
}
}
function Update () { var controller : CharacterController = GetComponent (CharacterController);
//Rotate around Y axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
//Move forward & backward
var forward = transform.TransformDirection (Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove (forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,
GameObject.Find("spawnPoint").transform.position,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
}
}
function LateUpdate() { if (dead == 1) { transform.position = Vector3(0,4,0); gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10); dead = 0; }
if (gotHit == 1)
{
if (tumbleSpeed < 1)
{
// we're not hit anymore..... reset & get back to the game
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = 0;
}
else
{
// we're hit!!!! Spin our character around
transform.Rotate(0, tumbleSpeed * Time.deltaTime,0, Space.World);
tumbleSpeed = tumbleSpeed - decreaseTime;
decreaseTime += decayTime;
}
}
}
@script RequireComponent(CharacterController)
the var Dead and GotHit ment to be true false statements. But when it's a true or false statement it does not work ad all.
In this script i fixed it whit the 0 and 1.
I think that's normal behavior. Do you get any compile error? If you do, perhaps you can post the code?
You aren't using true and false because they aren't changing color? ... Really??? Now, let's think about this. One of two things is happening here. Either the two most common keywords in a program$$anonymous$$g language just "stopped working", or whatever code editor you're using has broken, and syntax hilighting has been disabled. -- Your true and false are fine. Use them if you don't get errors, don't rely on the color of the word to deter$$anonymous$$e whether or not there's an error. Also, don't use 0 and 1 in place of false and true since they aren't the same thing.
@SpikeX, man, chill... :) It is a legitimate question. Any time I have something unusual going on in my code, unexpected warnings, odd auto-completions, whatever, I try to figure it out, because it usually means something is wrong somewhere. $$anonymous$$aybe a typo, maybe I used a keyword for a variable name - but it's always something that's going to cause me problems eventually. :) And, he did say that true/false were not working.
@martijn, can you post the original code with true/false, so we can look at it? I don't see a problem there. And SpikeX does have one point - did true/false suddenly stop working? Or was it the first time you used it? Can you make a simple one-liner program that works, something like: "if (tmpvar == true) Debug.Log("working");"
@Cyclops I'm glad someone else said what I was thinking a couple hours ago when I read this question. @SpikeX I understand sometimes co$$anonymous$$g here I get a couple facepalm worthy questions myself but the point is to provide a helpful hand. You're a very knowledgeable fellow with obvious talent on this platform - just kill 'em with kindness, yo. ==
Answer by equalsequals · Jun 01, 2010 at 03:05 PM
I had a similar problem working in a different dev platform at one point, my first reaction to a problem like this is to simply cold boot, clear the cache and see if that fixes it.
It could be as simple as that, or it could be a problem with your .Net installation.
Cheers,
==
Your answer