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
    • Recent
    • Tags
    • Users
    • Login

    Global variable problem [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 502 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

      On 28/10/2014 at 10:57, xxxxxxxx wrote:

      Hi
      I'm trying to get global variables working - I have a strange problem where if make a comparison test - I can no longer change the value afterwards without crashing.

      for example...

      > import c4d
      >
      > from c4d import gui
      >
      > #Welcome to the world of Python
      >
      >
      >
      >
      > def main() :
      >
      >     if x != y:
      >
      >         y = 0
      >
      >         print y
      >
      >
      >
      >
      > if __name__=='__main__':
      >
      >     x = 3
      >
      >     y = 7
      >
      >     main()
      >
      >
      >
      gives the error,
      UnboundLocalError: local variable 'y' referenced before assignment

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

        On 28/10/2014 at 12:39, xxxxxxxx wrote:

        Hi,

        an example.

          
        import c4d  
          
          
        def settings() :  
          global x,y  
          x=3  
          y=6  
          return x,y  
          
        def main() :  
          global x,y  
          settings()  
            
          if x != y:  
              y = 0  
              print y  
          
        if __name__=='__main__':  
          main()  
          
        

        Best wishes
        Martin

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

          On 28/10/2014 at 12:56, xxxxxxxx wrote:

          Thanks for that Martin!

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

            On 28/10/2014 at 13:24, xxxxxxxx wrote:

            you´re welcome

            another one:
            depends on what you´re going to do

              
              
            import c4d  
              
            global x,y  
            x=6  
            y=5  
              
              
            def main() :  
              global x,y  
                
                
              if x != y:  
                  y = 0  
                  print y  
              
            if __name__=='__main__':  
              main()  
              
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 28/10/2014 at 14:04, xxxxxxxx wrote:

              yeah that looks a bit simpler - cheers 🙂

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