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 HomeSpunGames · Apr 15, 2012 at 03:53 PM · javascriptnooborderexecute

How does Unity "read" JavaScript code?

If I have an update function with many different statements, does Unity execute them all at once every frame, or execute them line by line? For example, lets say I have a control scheme that first has an if statement that moves the character side to side, then another if statement that moves the character up and down. Will Unity first move the character side to side, then up and down, or compute both movements at the same time?

Sorry if this is a really basic question (new to Unity), but it would be really helpful to know how Unity "thinks" so I better organize my code.

Thanks!

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

3 Replies

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

Answer by Piflik · Apr 15, 2012 at 03:57 PM

Line after line...just like everything else. There is no way to do different things at the same time. Often later lines depend on changes done in earlier lines...if anything did calculate different lines simultaneously, it would be next to impossible to write any code at all.

Comment
Add comment · Show 5 · 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 HomeSpunGames · Apr 15, 2012 at 03:59 PM 0
Share

I just remember hearing something like that somewhere, but line by line execution is what I thought, I just wanted to make sure!

avatar image fafase · Apr 15, 2012 at 04:35 PM 0
Share

Well, it actually does makes many thing at once at the processor level (Pipelines can generally do 5 different actions at once) but the coder does not see any of that and it is far beyond any of us to be able to know how the assembly codes are going to be generated.

avatar image Eric5h5 · Apr 15, 2012 at 05:30 PM 2
Share

You can use threads to do different things at the same time (literally at the same time if you have more than one core, otherwise it's really just rapidly switching between threads). That's a relatively advanced topic though, since it's easy to mess up and make things that fail randomly.

avatar image Owen-Reynolds · Apr 16, 2012 at 03:41 AM 0
Share

But seriously, you know this person has no program$$anonymous$$g background at all? Because if you've written print Hello World; print newLine;, you learn that rule.

avatar image fafase · Apr 16, 2012 at 05:04 AM 1
Share

Yep, but by giving clues on advanced topics, who knows he might go and check and learn something about it.

avatar image
1

Answer by fafase · Apr 15, 2012 at 03:59 PM

It takes one statement at a time, nut for a coroutine it jumps out of the update and put it on hold until the function returns. Smae when you have a callback function (Collision).

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 aldonaletto · Apr 15, 2012 at 06:01 PM 0
Share

That's important thing to remember! Coroutines return to the caller code when the first yield is executed, and are resumed automatically each frame until they end.

avatar image
-5

Answer by maroonrs2 · Apr 16, 2012 at 07:02 AM

Technically, you all are right and wrong. What is does is use somethingm im refering to Lua as a coder for it, is (string.gmatch(arg1,arg2)) or match the string. It goes word, space, word, space and so on. Thats why when you play a code thats correct and you see if you use if's instead of else if's then you can do multiple things at once because it is matching the code up word by word. Enough said! BTW I hope ur under 15 cause im 15 -.-

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 fafase · Apr 16, 2012 at 06:52 PM 7
Share

Technically you are wrong and wrong.

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

7 People are following this question.

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

Related Questions

How do I make a respawn system? 1 Answer

Camera movement(I have no clue how to code) 0 Answers

Can someone review a short script and tell me where I've gone wrong? [JavaScript] 1 Answer

String.Split() Function Issues 1 Answer

Spawn object in random areas 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