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

Username:   Password: 
 RegisterRegister   
 Find a variable in an array that points to anyclass
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 7:50 pm   Post subject: Find a variable in an array that points to anyclass

What is it you are trying to achieve?
I have an array that points to anyclass. This is because I need to hold data from several different classes so I can check them all.


What is the problem you are having?
I cannot access a variable from the instance of a class in the array because the variable is not exported by anyclass.


Describe what you have tried to solve this problem
I checked the indice of the array with objectclass and found that it is the proper class, and I am confused as to why Turing still thinks the indice of the array is of type objectclass.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
http://pastebin.com/B80VgxpD
The array that points to anyclass is noun.
Way at the bottom I am doing a test to find the "name" of noun(1), but it throws the previously listed error at me.

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




PostPosted: Wed Jun 26, 2013 7:59 pm   Post subject: RE:Find a variable in an array that points to anyclass

You should create another class that exports 'name', and have all your other classes extend it. Then adjust your array to point to this class instead of anyclass.
Timothy Willard




PostPosted: Wed Jun 26, 2013 8:31 pm   Post subject: Re: Find a variable in an array that points to anyclass

Yeah, I was considering that. I am still curious as to why it is happening though.

I am a person who likes to understand, and I would like to understand why I can't call up the variable inside the array when Turing says that it is of the class Weapon, not anyclass.
Insectoid




PostPosted: Wed Jun 26, 2013 9:00 pm   Post subject: RE:Find a variable in an array that points to anyclass

If you iterate over the array, Turing doesn't know what class those objects are (other than anyclass). If you ask for variable X, Turing doesn't know if it exists in that object. It might exist in some or even all of the objects in the array, but if it tries to get it from an object that doesn't have it, really weird things can start happening. I don't know if Turing supports casting objects, but you might be able to use cheat() to turn it into a Weapon if you know for a fact that that object is a weapon.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: