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
1
Question by Xathos · Mar 07, 2011 at 12:43 AM · listdebuggingboobce0019typecasting

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?

Comment
Add comment · Show 1
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 Bunny83 · Mar 07, 2011 at 12:58 AM 1
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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 ;)

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 cregox · May 07, 2012 at 05:59 PM 0
Share

you just forgot to accept your own answer! :)

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

No one has followed this question yet.

Related Questions

A node in a childnode? 1 Answer

List of Quaternions - NullReferenceException with types or type check errors without? 1 Answer

Using lists or arrays of transforms in Boo. 1 Answer

'time' not a member of 'Object' 1 Answer

Small problem with a List. 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