Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Global variables

    Scheduled Pinned Locked Moved PYTHON Development
    7 Posts 0 Posters 694 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 11/12/2012 at 01:23, xxxxxxxx wrote:

      I created a plugin tag which uses a global list.
      So declared as global ylist[].

      However, when I have two objects each with the tag, it looks as if both tag uses this same global list.
      So, global is indeed really global and not just global within the tag.

      How can I define a variable that is only global within the tag?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 11/12/2012 at 03:01, xxxxxxxx wrote:

        Originally posted by xxxxxxxx

        How can I define a variable that is only global within the tag?

        Please avoid globals at all cost. If you need the list to be only global to a tag instance, declare it as member of the plugin class.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 11/12/2012 at 03:04, xxxxxxxx wrote:

          Ok, thanks.
          How to declare it as member of the plugin class?
          And is it then local to the tag plugin?

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 11/12/2012 at 03:13, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            How to declare it as member of the plugin class?

            Simply using Python class constructor:

            class MyTagPlugin(plugins.TagData) :
                
                def __init__(self) :
                    self.ylist = []
                
                ...
            

            Originally posted by xxxxxxxx

            And is it then local to the tag plugin?

            Yes as it's member of a class, its value is different between instances.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 11/12/2012 at 03:43, xxxxxxxx wrote:

              Thanks, I'll try this out.

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 11/12/2012 at 03:44, xxxxxxxx wrote:

                not sure if this is true, but i think he doesn't meant the plugin class itself, but the namespace 
                of the plugin. when you declare a global constant like PLUGIN_ID and then declare it as a global
                variable from within a method or a class too, you can actually overwrite the constant with it.
                not sure if this intended or just a sideeffect of the typefree approach.

                there is no *solution* for this problem. you have either use methods (parameters) or a more 
                fancy message/hook/event based system  to pass your variables from class to class.

                http://stackoverflow.com/questions/1092531/event-system-in-python

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 11/12/2012 at 08:08, xxxxxxxx wrote:

                  It works very good.
                  I can now have multiple instances of the same plugin.

                  Thanks.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post