Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Convert a string into a variable name.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Timothy Willard




PostPosted: Wed Jun 26, 2013 5:07 pm   Post subject: Convert a string into a variable name.

What is it you are trying to achieve?
I want to be able to take a string (for example: var teststring := "maxHealth") and be able to convert it into a variable name so it could be used (ex. if I were to type teststring := 50 with the syntax it would set the variable maxHealth to 50, not try to set the string teststring to 50).


What is the problem you are having?
As far as I am aware, there is no syntax for this in Turing, and I will have to hardcode each string in with an if statement (i.e.
Turing:

 if teststring := "maxHealth" then
maxHealth := 50
end if




Describe what you have tried to solve this problem
I have looked around on google, and found answers in other programming languages (I think square brackets do what I want in javascript, but I didn't look to closely). I can't find it in Turing, and I assume it doesn't exist, but I am checking to make sure.

Please specify what version of Turing you are using
4.1
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Jun 26, 2013 5:26 pm   Post subject: RE:Convert a string into a variable name.

What you're talking about it usually called reflection: http://en.wikipedia.org/wiki/Reflection_(computer_programming) . A lesser version is introspection, which is a much weaker related idea.

Turing has no support for reflection or introspection.
Zren




PostPosted: Wed Jun 26, 2013 8:08 pm   Post subject: RE:Convert a string into a variable name.

Quote:
found answers in other programming languages (I think square brackets do what I want in javascript, but I didn't look to closely).


Those are called dictionaries. They tend to use the same syntax for array indexes as well.

They are also known as Mappings in Java (Map and HashMap). They are key-value store objects. Turing doesn't have a native implementation for them.

There are a Turing libraries that implements dictionaries, or rather HashMap, though it's very verbose.
http://compsci.ca/v3/viewtopic.php?t=20302

OpenTuring has a HashMap implementation, but that won't help you if you if you're submitting for a school project.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: