Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by martijn v · Jun 01, 2010 at 09:17 AM · javascriptide

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.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Extrakun · Jun 01, 2010 at 09:20 AM 0
Share

I think that's normal behavior. Do you get any compile error? If you do, perhaps you can post the code?

avatar image qJake · Jun 01, 2010 at 09:27 AM 2
Share

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.

avatar image Cyclops · Jun 01, 2010 at 01:53 PM 1
Share

@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.

avatar image Cyclops · Jun 01, 2010 at 01:56 PM 0
Share

@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");"

avatar image equalsequals · Jun 01, 2010 at 03:02 PM 0
Share

@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. ==

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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,

==

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Script not working (Java script) 2 Answers

How to Select between two prefabs randomly ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges