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 dansav · Feb 27, 2012 at 12:47 AM · javascriptiosiphonepragma

Help converting javascript to ios iphone scripting

I have a large unity3d javascript script I am trying to run on iphone. I'm getting tons of errors about variables not having their types defined. If I put # pragma strict at the top of the script it shows the errors in the unity compiler console.

My question is do I have to redefine all these using var? Or is there some shortcut setting that I can use to bypass all the errors?

What about arrays? Right now I have javascript Arrays like myarray=new Array(); Should I just use something like myarray=Vector3[];

I have an array full of rotations. What kind of array is that? Quaternions, Vector4? I use lots of hashtables how do I define ahead of time what's going in those?

What about functions? Some functions complain others do not. Do I define the arguments in the function declaration?

function myfunction(a:int,b:int);

Is there any documentation that says everything you have to do to go from javascript to iphone? -- things like eval() does not work, or that you have to define every variable etc... use built in arrays, etc...

Thanks,

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 dansav · Feb 27, 2012 at 01:01 AM 0
Share

How would I do an array of hashtables on iphone? animations=new Array(); animations[0]=new Hashtable();

2 Replies

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

Answer by Eric5h5 · Feb 27, 2012 at 01:23 AM

Never use Array, never use Hashtable. If you have a fixed-size array, use int[], Vector3[], etc. (As for rotations, look in the docs, it always tells you the type of everything.) If you have a variable-sized array, use List. Use Dictionary instead of Hashtable. And yes, you must always define the types in a function declaration.

Comment
Add comment · Show 4 · 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 Default117 · Feb 27, 2012 at 01:26 AM 0
Share

Yeah forgot to mention that as well. As far as i knew you always had to define the types and return types for functions, how is it possible to not do so?

avatar image dansav · Feb 27, 2012 at 01:30 AM 0
Share

Dictionary and List are .net functions? is that correct, not unity?

avatar image Eric5h5 · Feb 27, 2012 at 01:37 AM 0
Share

You don't have to define types if the compiler can infer it from the value supplied.

 var foo = 5;  // foo is an int
 var foo = .5;  // foo is a float

 function TrueOrFalse () {
     return (Random.value < .5);
 }
 // TrueOrFalse is a boolean

The type doesn't change at runtime so it's not dynamic typing. What you should not do is this, because the type can't be inferred:

 function Blah (x, y)

Ins$$anonymous$$d,

 function Blah (x : int, y : int)

Dictionary and List are .net, yes. It's the same as C# except for the extra "."

 var foo = new List<int>();  // C#
 var foo = new List.<int>();  // JS
avatar image dansav · Feb 27, 2012 at 01:50 AM 0
Share

Thanks now I get it completely. I have a ton of work todo. The combined total of these comments would make a great addition to the unity docs for all the javascript coders.

avatar image
1

Answer by Default117 · Feb 27, 2012 at 01:11 AM

Have a read of this document: http://unity3d.com/support/documentation/Manual/iphone-GettingStarted.html

By default iOS turns of dynamic casting, which essentially would do the same thing when you do #pragma strict. You just need to ensure that you declare all your variable data type, which you really should be doing anyway, its just good practice.

 var m_string : string;
 var m_int : int;
 var m_rotation : Quaternion;
 var m_jArray : Array;
 varm_bullitinArray1 : GameObject[];
 varm_bullitinArray2 : int[];

and so forth

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

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

How to save data on iOS? 1 Answer

Strongly Typed Javascript on iOS 2 Answers

Zooming in and out on iPhone 1 Answer

What shader blending modes don't work on iOS? 1 Answer

Make an object move in the direction of touch 0 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