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 Ian-McCleary · Aug 22, 2013 at 08:12 PM · errorfoundexpecting

Error expecting ) found |

So i have an error in my script that i cant fix and i cant test my FPS game without. I know this is an easy fix but i am new to javascript and i dont even have a key that allows me to type | but i am able to copy and paste it.

The series of videos i am watching told me to put || but then i get the error in the title. So i tried putting only one | and then it came up with a different error

Operator '|' cannot be used with a left hand side of type 'float' and a right hand side of type 'float'.

I dont even know what that means!! If you know what is wrong then please help or if you know how to fix it i could really use your help too.

 var Fire : String;
 var Reload : String;
 var Idle : String;
 var Wlak : String;
 
 function Update() 
 {
     if(Input.GetAxis("Vertical") | Input.GetAxis("Horizontal")){
         animation.Play(Walk);
     }
     else 
     {
         animation.Play(Idle);
     }
 }
 
 function FireAnim() 
 {    
     gameObject.animation.Play(Fire);
 }
 
 function ReloadAnim()
 {        
     
     animation["Reload"].speed = (animation["Reload"].clip.length / Gun.ReloadTTime);
     animation.Play(Reload);
 }
Comment
Add comment · Show 1
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 Steven-1 · Aug 22, 2013 at 08:30 PM 0
Share

on some keyboards the "|" key is displayed with a gap inbetween (kinda like a vertically stretched ":"). I've never heard of a keyboard without the "|" key.

3 Replies

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

Answer by perchik · Aug 22, 2013 at 08:13 PM

So a single bar means Bitwise OR. Every number is stored as a bunch of 1s and 0s, and bitwise OR compares those 1s and 0s.

What you want is actually the double bar ||

I wonder if perhaps you are running into your error because the character for the bar that you are copying is wrong?

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
avatar image
0

Answer by Loren-Logic · Aug 22, 2013 at 08:53 PM

Try the shift-\ key over the ENTER key. Try isolating both OR clauses with more parentheses, and add the arguments, like this:

if((Input.GetAxis("Vertical") == true) || (Input.GetAxis("Horizontal") == true)){ ... } I've run across occasions when .net can't OR correctly without explicit precedence. Although you certainly did have an error in your code with just one pipe (|) symbol. You tried to do a bitwise comparison of two floating decimal values; your values to the left and to the right of the equal sign were both 'floats,' when integers are required. The double-pipe compares TRUE to TRUE or FALSE to FALSE or TRUE to FALSE or FALSE to TRUE. That's what you want.

Comment
Add comment · Show 1 · 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 ArkaneX · Aug 22, 2013 at 09:13 PM 0
Share

Additional parentheses are not required, and comparing to true will completely prevent it from working.

In JS this works:

 if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal"))

but if you compare value from GetAxis to boolean:

 if(Input.GetAxis("Vertical") == true || Input.GetAxis("Horizontal") == true)

then it won't work.

avatar image
0

Answer by lancer · Aug 22, 2013 at 08:57 PM

Input.GetAxis returns a float, you need to do something like this:

 if(Input.GetAxis("Vertical")  > 0| Input.GetAxis("Horizontal") > 0){
        animation.Play(Walk);
     }
     else 
     {
        animation.Play(Idle);
     }
 

 
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 ArkaneX · Aug 22, 2013 at 09:15 PM 0
Share

This is wrong answer. Firstly, because bitwise operator is still there. Secondly, because in JS it is enough to do:

 if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal"))

You don't have to compare results to any number.

And thirdly, because you only test using greater then operator. And what if negative float is returned?

avatar image perchik · Aug 24, 2013 at 03:20 AM 0
Share

Input.GetAxis() returns 0 if that axis is at it's default position. When you do an if on a float, if it's 0 it returns false, else it returns true. Usually this code is used to handle an axis that has moved, so the if statement only enters the body if the axis isn't at it's default position.

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

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

No appropriate version of 'UnityEngine.Object.Instantiate. Please Help :( 1 Answer

How can I convert this code to Unity Android? 1 Answer

What is wrong with these two lines of scripting? 1 Answer

CAN SOMEONE FINALLY HELP ME! 3 Answers

The code is giving me errors 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