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 reptilebeats · Jul 21, 2012 at 11:50 PM · functionvarible

storing a line of code as a reference/varible

hi I've looked everywhere but i can't seem to find out if i can do this, basically i won't to store something like

var switchMenu = menuSwitch.animation["areaToLevelSwitch"];

outside of a function so that other functions inside my script can use it, i can store it in a function fine, but would like to know if it is possible to store it outside a function.

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

Answer by Doireth · Jul 22, 2012 at 11:27 PM

I have never heard of storing code/expression as a variable and don't see how it would even make sense. Remember a variable declaration is the designation of memory based on the variable type. A line of code doesn't fit into any type be it primitive or reference.

Even if you were to store a line of code as a string you will need to parse the code, do syntactic and semantic checks and then have some compiler turn the code into machine instruction.

There is really no reason I can think of where this idea would be the solution or have I just misunderstood the question?

If it's just the reuse of code then:

 function Example() {
     // the code you'll want to reuse
 }
 
 function Update() {
     Example(); // use the stored code
 }

....should suffice.

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 reptilebeats · Jul 22, 2012 at 11:38 PM 0
Share

it was mainly just to store a reference which is used in about 6 different functions in one script, i didn't think it was possible, but you never know. i guess storing it in a function wouldn't make much difference, as to just writhing it at the top of each function... cheers

avatar image
0

Answer by ScroodgeM · Jul 22, 2012 at 07:20 AM

simply write your line outside function.

var switchMenu = ...;

function f1() { ...use switchMenu; }

function f2(some params) { ...use switchMenu; }

or i didn't understand your question???

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 reptilebeats · Jul 22, 2012 at 09:51 PM 0
Share

nah this doesn't work i have tried it.

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

get variable type and name 1 Answer

Invoke.Repeating doesn't really "care" about repeat time? 1 Answer

How to change GUI.DrawTexture with OnMouseEnter function? 1 Answer

You are not allowed to call this function when declaring a variable. 2 Answers

Function after iTween animation finished 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