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 yeoldesnake 1 · Jan 15, 2012 at 07:45 PM · variablestringnamehashtablehash

Converting String to Variable Name

I want to have the user specify a variable name as a string, and then have him change it's value. This is my current code which fails to work, something expected due to my zero experience with hash tables. What exactly does this one need to work properly? I may note that this is a potiful attempt at it and should not be used as a base to improve, i fail to understand what Hashtables are.

 var Hash : Hashtable;
 Hash = new Hashtable();
 
 if (consoleInterpretation[0] == "ModVal") {
     for (var gameObj : GameObject in GameObject.FindObjectsOfType(GameObject)) {
         if (gameObj.name == consoleInterpretation[1]) {
 
               gameObj.GetComponent(consoleInterpretation[2])
                      .Hash[consoleInterpretation[3]] = 
                       int.Parse(consoleInterpretation[4]);
 
         }
     }
 }
Comment
Add comment · Show 2
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 MarkFinn · Jan 16, 2012 at 05:53 AM 1
Share

$$anonymous$$ay I ask what you're using this for? It's not something that is commonly of any use in most systems and situations. This feels like a "What's the real question?" situation, where your own efforts to solve a problem have led to a rather strange set of follow-up questions.

avatar image yeoldesnake 1 · Jan 16, 2012 at 01:17 PM 0
Share

Well, i mainly want it so that i can modify a variable's value through a console similar to the one in the TES games.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MarkFinn · Jan 16, 2012 at 05:52 AM

Dynamic code management is a pretty obscure area. You'd be far better off creating an indexed array (Dictionary in C#, Hashtable in Java) of values and allowing the user change values in that table rather than using "real" variable names.

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 yeoldesnake 1 · Jan 16, 2012 at 01:16 PM 0
Share

However, i have no knowledge of such methods.

avatar image
1

Answer by gooncorp · Aug 15, 2012 at 02:43 AM

why would someone wanna do this? i can think of thousands of reasons. ive been struggling with this myself for some time. i am building a very advanced inventory system from scratch and it would make my life a lot easier if there was a format command to turn string into variable name. its not some mysterious thing its very basic....

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
avatar image
0

Answer by DaveA · Aug 15, 2012 at 03:13 AM

Answered here: http://answers.unity3d.com/questions/37010/getting-variable-name-from-a-string.html

I would avoid it as it could lead to all kinds of unwanted hacking and intrusions.

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

7 People are following this question.

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

Related Questions

String as Variable name 0 Answers

Is there a way to get the symbolic String name [editing name] of a variable at runtime? 1 Answer

transform.name value to a variable 2 Answers

Does Game objects names affect anything in build ?,does Game objects names affect anything? 1 Answer

String as variable name, reflection or dictionary or other 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