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 Alex Wroten · Nov 23, 2010 at 02:05 AM · variablesbooleandebugging

How to fix unstable boolean values? [possible bug]

Hello,

I am creating an override boolean value for a game project I am working on. Only when the "t" key is pressed does this override activate (Input.GetKeyDown), and it is reversed upon lifting the "t" key (Input.GetKeyUp). The problem is that the value seems to be toggling elsewhere in the code. It is very bizarre!

This is where it is called:

if (Input.GetKeyDown("t")){ objectTurret.GetComponent(turretOverlord).editModeGo(true); }else if (Input.GetKeyUp("t")){ objectTurret.GetComponent(turretOverlord).editModeGo(false); }

turretOverlord script functions

 function editModeGo(isEditMode : boolean){
     editOverride=isEditMode;
     spinnerAccess.GetComponent(turretSpinShoot).setEdit(!editOverride);
 }

 function Update(){
     if (!editOverride){
         spinnerAccess.GetComponent(turretSpinShoot).setEdit(gamePlayer.GetComponent(playerMoveScript).editMode);
         // playerMoveScript.editMode is ALWAYS true for this particular problem
     }
 }

turretSpinShoot.

private var editMode : boolean = false;

function Update () { print (editMode); }

function setEdit(modeOn : boolean){ editMode=modeOn; }

When I run this, the behavior changes each time I press/unpress "t": 1st time: "False", followed by an infinite stream of "True" 2nd time: a repeating stream of "False" then "True" then "True" 3rd time: a repeating stream of "False" then 4x "True" 4th time: a repeating stream of "False" then 6x "True" 5th time: a repeating stream of "False" then 8x "True"

What in the world could be causing this???!

Comment
Add comment
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

1 Reply

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

Answer by Loius · Nov 23, 2010 at 04:33 AM

If your "if input" stuff is actually outside a function, you'll want to move it inside a function (probably update).

Additional:

Perhaps the problem is that GetKey expects a KeyCode argument. Try replacing "t" with KeyCode.T

Comment
Add comment · Show 2 · 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
avatar image Alex Wroten · Nov 23, 2010 at 04:54 PM 0
Share

Actually, that "if input" stuff is in an Update function. Sorry, forgot to copy that.

avatar image Loius · Nov 23, 2010 at 05:00 PM 0
Share

Ah, okay. The problem might be that Get$$anonymous$$ey uses $$anonymous$$eyCodes as parameters, and the string "t" might be interfering with its thinking.

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

Array with boolean variables? 3 Answers

Change a Variable on Key Down 5 Answers

Some Boolean "Action" Trouble 2 Answers

Access other variables please help :( 1 Answer

Why does monobehavior in if statement compiles? 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