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

    Using variables with python tag

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 232 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 08/06/2012 at 09:36, xxxxxxxx wrote:

      I am beginning to think I do not quite understand the relation between cinema 4d and python.
      I have a python tag with a some simple code (see below).
      What I want to achieve is store data on frame x and use in frame x+1.

      For frame 0 it is ok, but for other frames I get the message "referenced before assignment".
      I do understand the message and why it is given, but it tells me that the code is executed every frame and the variables are initialized every time.

      I can use userdata or the BaseContainer, that solves my issues, but I would like to understand.
      I also tried global variables, but that didn't help either.

      What to do?

      def main() :

      print "\n----------\n"

      frame = doc.GetTime().GetFrame(doc.GetFps())
      if (frame ==0) :
        varx = 0
      else:
        varx = varx + frame

      print "varx: ", varx

      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 08/06/2012 at 09:43, xxxxxxxx wrote:

        Sorry, I did not search the forum before asking.

        The solution is simple.
        Just init the variable outside main and define it as global within main.

        varx=-1

        def main() :

        global varx

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