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 BitCrafty · Feb 18, 2012 at 07:24 PM · animationjavascriptmovementvariablefunction

Javascript Movement Script. Why am I getting these errors?

Hey,

I am currently working on a input/movement script for a simple top-down 2D RPG using javascript.

Here is what I have written so far:

 #pragma strict
 
     /* ========== Define Variables ========== */
 
 var moveSpeed : float = 10.0;
 var playerSprite : PackedSprite;
 
 
 
 
 function Update () {
 
 var thisTransform : Transform;
 var moving : boolean;
 
 var movingLeft : boolean = false;
 var movingRight : boolean = false;
 var movingUp : boolean = false;
 var movingDown : boolean = false;
 
 var wasMovingLeft : boolean;
 var wasMovingRight : boolean;
 var wasMovingUp : boolean;
 var wasMovingDown : boolean;
 
 var movement : float;
 var horMoveDir : int;
 var verMoveDir : int;
 
 
 thisTransform = transform;
 
     /* ========== Keyboard Input ==========*/
 
     if(Input.GetKey("left")) {
         horMoveDir = -1;
         verMoveDir = 0;
         wasMovingLeft = true;
         wasMovingRight = false;
         wasMovingUp = false;
         wasMovingDown = false;
     
         
         if(!movingLeft) {
             movingLeft = true;
             movingRight = false;
             movingUp = false;
             movingDown = false;
             AnimateWalk();
         }
     }
         
     if(Input.GetKey("right")) {
         horMoveDir = 1;
         verMoveDir = 0;
         wasMovingLeft = false;
         wasMovingRight = true;
         wasMovingUp = false;
         wasMovingDown = false;
     
         
         if(!movingRight) {
             movingLeft = false;
             movingRight = true;
             movingUp = false;
             movingDown = false;
             AnimateWalk();
         }
     }
         
     if(Input.GetKey("up")) {
         horMoveDir = 0;
         verMoveDir = 1;
         wasMovingLeft = false;
         wasMovingRight = false;
         wasMovingUp = true;
         wasMovingDown = false;
 
         
         if(!movingUp) {
             movingLeft = false;
             movingRight = false;
             movingUp = true;
             movingDown = false;
             AnimateWalk();
         }
     }
         
     if(Input.GetKey("down")) {
         horMoveDir = 0;
         verMoveDir = -1;
         wasMovingLeft = false;
         wasMovingRight = false;
         wasMovingUp = false;
         wasMovingDown = true;
         
 
         
         if(!movingDown) {
             movingLeft = false;
             movingRight = false;
             movingUp = false;
             movingDown = true;
             AnimateWalk();
         }
     }
 
         
     /* ========== Animate Walk ==========*/
         
     function AnimateWalk() {
         if(movingLeft) {
             playerSprite.PlayAnim(3);
         }
         
         if(movingRight) {    /*Try "else if" if this doesn't work*/
             playerSprite.PlayAnim(2);
         }
         
         if(movingUp) {
             playerSprite.PlayAnim(0);
         }
         
         if(movingDown) {
             playerSprite.PlayAnim(1);
         }
     }
     
 }


The Unity Console is returning the following errors for it:

 (111,18): BCE0044: expecting (, found 'AnimateWalk'.
 (111,31): UCE0001: ';' expected. Insert semicolon at the end.
 (112,17): BCE0043: Unexpected token: if.
 (112,31): UCE0001: ';' expected. Insert a semicolon at the end.
 (113,49): BCE0044: expecting :, found ';'.

(line 111 is the first after "Animate Walk" comment)

I have no idea why. These characters obviously shouldn't be where it says they should. (should they? :S).

I am very new to Unityscript and I get the feeling I'm missing something ridiculously obvious, but I've spent most of the day trying to figure this out and it's baffling me. Anybody lend a hand?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Sharon Hanlon · Feb 18, 2012 at 08:47 PM

Your AnimateWalk function is inside of your Update function. Move the } from the last line and put it before the function AnimateWalk() line.

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 BitCrafty · Feb 18, 2012 at 10:13 PM 0
Share

Damn. That simple.

Thanks, I'd probably never have spotted that and still be pulling my hair out now.

Everything is working fine, except my animations. Only the up animation seems to work. =[ (I ended up using else if.) Anyone any idea why? :S

avatar image
0

Answer by Sharon Hanlon · Feb 18, 2012 at 10:17 PM

If you're using the tk2DSprite package for your animation, make sure all sprites in the collection have a "bottom left" anchor point. If you're not using that, sorry, I have no idea.

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 BitCrafty · Feb 18, 2012 at 10:56 PM 0
Share

I'm using Sprite $$anonymous$$anager 2, the anchor point is set to the texture offset (0, 0, 0,), changing to bottom left didn't help. Thanks anyway.

I found out my problem is that when I build atlases only the first animation (walkup) is beig drawn, so there is no animation to access on the atlas.

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

6 People are following this question.

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

Related Questions

Enemy circles player instead of attacking. 1 Answer

How do you achieve variables and functions that are global between scenes? What is the BEST way? 1 Answer

CharacterMotor problem (Js) 1 Answer

Horizontal axis not working after animation 1 Answer

variable = true from another script 2 Answers


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