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 pwolf · Dec 16, 2012 at 12:34 AM · javascriptmultiplepragmastrict

beginner question- several errors

I've been attempting a tutorial on creating an achievement system, however, the tutorial is not taking #pragma strict into consideration, and as a beginner, it is causing many difficulties. I would probably be better off turning off pragma strict and following the tutorial as it was done originally, however, I do not wish to learn improperly! My latest errors are as follows:

Assets/Scripts/AchievementManagement.js(13,10): BCE0044: expecting (, found 'playerMoved'. Assets/Scripts/AchievementManagement.js(14,1): BCE0044: expecting :, found '{'.

the two scripts are as follows:

Movement.js

 #pragma strict
 
 var achievementManagerScript: AchievementManagement; 
 var speed: int = 5;
 private var cc: CharacterController;
 
 function Start ()
 {
     cc = GetComponent(CharacterController);
 }
 
 function Update () 
 {
     if(Input.GetAxis("Horizontal") || Input.GetAxis("Vertical"))
     {
         achievementManagerScript.playerMoved();
     }
     
     cc.Move(-Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0,
     Input.GetAxis("Vertical") * speed * Time.deltaTime));
     
 }
 
 function OnTriggerEnter(col: Collider)
 {
     if(col.gameObject.tag == "Coins")
     {
         Destroy(col.gameObject);
     }
 }

and the final one is: AchievementManagement.js

 #pragma strict
 
 var firstStepTex: Texture; 
 
 private var firstStepTaken:boolean;
 private var edgeMargin;
 
 function Start()
 {
     edgeMargin = Screen.width * .05;
 {
 
 function playerMoved()
 {
     if(!firstStepTaken)
     {
         unlockAchievement(firstStepTex);
         firstStepTaken = true; 
     }
 }
 
 function unlockAchievement(achievementTex:Texture)
 {
     var go:GameObject = new GameObject("Achievement Object");
     go.transform.position = Vector3(0,0,0);
     go.transform.localScale = Vector3(0,0,0);
     var guitex: GUITexture = go.AddComponent(GUITexture) as GUITexture;
     guitex.texture = achievementTex;
     guitex.pixelInset.width = achievementTex.width;
     guitex.pixelInset.width = achievementTex.height;
     guitex.pixelInset.x = Screen.width - achievementTex.width - edgeMargin;
     guitex.pixelInset.y = Screen.height - achievementTex.height - edgeMargin;
 }



Any help to find the errors, and any advice for avoiding further errors is greatly appreciated!

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
2
Best Answer

Answer by clunk47 · Dec 16, 2012 at 01:16 AM

You had a backwards bracket for function Start, like so:

 function Start()
 {
 
 {

Then you didn't define edgemargin as a float, the system thought it was an object. That's about it, otherwise everything seems fine. Try replacing AchievementManagement.js with this.

 #pragma strict
 
 var firstStepTex: Texture; 
 
 private var firstStepTaken:boolean;
 private var edgeMargin : float;
 
 function Start()
 {
     edgeMargin = Screen.width * .05;
 }
 
 function playerMoved()
 {
     if(!firstStepTaken)
     {
        unlockAchievement(firstStepTex);
        firstStepTaken = true; 
     }
 }
 
 function unlockAchievement(achievementTex:Texture)
 {
     var go:GameObject = new GameObject("Achievement Object");
     go.transform.position = Vector3(0,0,0);
     go.transform.localScale = Vector3(0,0,0);
     var guitex: GUITexture = go.AddComponent(GUITexture) as GUITexture;
     guitex.texture = achievementTex;
     guitex.pixelInset.width = achievementTex.width;
     guitex.pixelInset.height = achievementTex.height;
     guitex.pixelInset.x = Screen.width - achievementTex.width - edgeMargin;
     guitex.pixelInset.y = Screen.height - achievementTex.height - edgeMargin;
 }
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 pwolf · Dec 16, 2012 at 02:38 AM 2
Share

Thank you so much! The error messages were really confusing. I probably never would have found that without your help!

avatar image clunk47 · Dec 16, 2012 at 03:03 AM 1
Share

No problemo. If you don't $$anonymous$$d, you can also vote up the answer (thumbs up icon) :)

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

10 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

Related Questions

Multiple scripts with the same name issue 1 Answer

Can't use for-in statement in strict javascript. 1 Answer

Spawning random questions at a time 1 Answer

Why am I getting a "NullReferenceException" for a Instantiate line? 1 Answer

car moving sideways 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