- Home /
Force typcasting of member objects in a List? (Boo)
I'm trying to create an editor script to edit data contained within a sequence of objects; the best way to do this would of course be to contain these objects within a dynamic list (as opposed to a static array, which works). The problem is that as lists can a wide variety of objects, I've been getting compiler errors when I try to access a member variable of one of the list items: Assets/Editor/ConversationTreeEditor.boo(10,22): BCE0019: 'name' is not a member of 'object'.
I believe that there's a way to typecast member objects of a list in C# (List nodes = new List (); - right?), though I'm not sure how to do that in Boo. I have come up with the following code, which should not cause any run time errors (accessing member variables is bypassed if the given object doesn't pass a typecheck), but it has been unable to pass Unity's debugging system. Same goes for try/except blocks.
import UnityEngine import UnityEditor
[CustomEditor(ConversationTree)] class ConversationTreeEditor (Editor):
def OnInspectorGUI ():
for node in target.nodes:
if node isa ConversationNode:
node.name = EditorGUILayout.TextField("Name", node.name)
if GUILayout.Button("+"):
newNode = ConversationNode()
target.nodes += [newNode]
Since I can't run any of my code if I have compiler errors (Unity 3 made sure of that), this problem has brought my work to a grinding halt. I'm at a bit of a loss here... any suggestions?
This is the first boo script I've ever seen here. ;) Well i don't know a bit about boo or python but google gives me that link about typecasting in boo: http://boo.codehaus.org/Casting+Types
. +1 because i think there have to be some boo users around that can answer this question.
Answer by Xathos · Mar 07, 2011 at 03:51 AM
Okay, I've found the solution: just typecast the member variable in the for statement:
import UnityEngine import UnityEditor
[CustomEditor(ConversationTree)] class ConversationTreeEditor (Editor):
def OnInspectorGUI ():
for node as ConversationNode in target.nodes:
node.name = EditorGUILayout.TextField("Name", node.name)
if GUILayout.Button("+"):
newNode = ConversationNode()
target.nodes += [newNode]
Curiously enough this occurred to me when I was trying to puzzle out how the C# foreach construct worked, and the compiler notified me that I had to add an identifier ;)