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
1
Question by aman_jha · Jun 22, 2014 at 01:04 PM · c#androidjavascriptdynamiccompiler

What is Javascript dynamic typing and type inference on initialization?

Hey Unitarians! (Specifically Android Javascript programmers..)

I'm in a bit of a spot of trouble. I made a game with a ton of javascripts that were initially going to be developed for desktop. I changed my mind and switched to Android. I got a bazillion compile errors, and after much google hunting, Unity told me what I did wrong: http://docs.unity3d.com/Manual/android-GettingStarted.html. At near the end of this URL, it says,

For performance reasons, dynamic typing in JavaScript is always turned off in Unity Android, as if #pragma strict were applied automatically to all scripts. This is important to know if you start with a project originally developed for the desktop platforms since you may find you get unexpected compile errors when switching to Android; dynamic typing is the first thing to investigate. These errors are usually easy to fix if you make sure all variables are explicitly typed or use type inference on initialization.

So I know that I should have made it in C Sharp, like most of my other Android projects. However, I have no idea how to convert Javascripts to C Sharp and I imagine that even if I did it would take a lot of time that I don't have.

They show two solutions at the end of their paragraph. They say that I can "make sure all variables are explicitly typed" I imagine this would take a lot of unnessesary time, and either way I'm not 100% sure what they mean on that. They also say something called "use type inference on initialization". As my last resort, I'm interested in this. Can anyone tell me what it is and what to do? Or if you could clear up dynamic typing in general as well, that'd be great since I believe I only have a on-the-surface idea of what's happening here.

Your awesome Indie developer, Aman Jha

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 meat5000 · Jun 22, 2014 at 05:14 PM

My answer disappeared again... I'll re-write it.

Unity is telling you to tell it what Type your variables are as you declare them rather than letting it work that out based on the data that's put in.

so,

 var myFloat : float = 0.0;

or

 var myFloat = 0.0;

Rather than

 var myFloat;
 myFloat = 0.0;




Comment
Add comment · Show 6 · 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 aman_jha · Jun 22, 2014 at 05:01 PM 0
Share

:O It's that simple?? Thanks so much! I'm going to check it out right now after I finish wrestling with my non-cooperative GUI elements.

avatar image Bunny83 · Jun 22, 2014 at 10:31 PM 2
Share

@meat5000: That's actually wrong, or to be more precise, both of your examples are actually right ;)

In the first one you explicitly type your variable manually. In your second example you use type inference to type the variable which is also ok.

What doesn't work is this:

 var myFloat;              // dynamic type
 
 // ...
 myFloat = 5;              // dynamic... int
 myFloat = "Hello world!"; // dynamic... string
 myFloat = 0.0;            // dynamic... float


In this case myFloat doesn't have a type and would be a "dynamic type" which isn't supported on mobile and should even be avoided on any platform.

avatar image meat5000 ♦ · Jun 22, 2014 at 11:00 PM 0
Share

Cheers for clearing that up. I got some errors using the second one a long time ago and I've avoided it like the plague ever since :D

I'll update my answer.

Better? :D

$$anonymous$$y primary language is actually AS$$anonymous$$ ^ ^

avatar image Bunny83 · Jun 22, 2014 at 11:39 PM 0
Share

@meat5000: Yes, better :D But i bet you don't use AS$$anonymous$$ in Unity, or do you code in IL? x)

I used x86 assembler for quite a long time as well as PIC assembler during my PIC time.

$$anonymous$$y primary languages are now: C#, LUA, C++, Java, Delphi. I never use UnityScript ;)

avatar image meat5000 ♦ · Jun 22, 2014 at 11:49 PM 0
Share

lol I'd have to be Autistic to pull that one off :D

PICs are awesome :P Got a few 877A propping up my desk :D I was halfway through a lil USB project when I got distracted by Unity.

Java was my first OO. Got heavily in to C, Elec-Eng stylee. $$anonymous$$y skills are fading though. I can feel my brain cells committing suicide :D

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

5.4 No autocompletion in unity or MonoDevelop, how to compile the code JS & C#? 0 Answers

About ListItems in Unity3D 1 Answer

Unity editor style camera script 1 Answer

Flying AI Planes 0 Answers

Make an object move when clicking a GUI button? 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