Topic outline

  • Kia ora Guest user

    Welcome to CGI506 Technical Development 1, S2-20. In this course you will be developing basic skills and knowledge of programming for animation and game development and to develop custom tools and functions for a successful production pipeline.

    On completion of this course you will be able to:

    1. Investigate and compare different programming languages used for animation, visual effects and real time applications. 
    2. Evaluate the effectiveness of different scripting/programming languages for selected applications. 
    3. Select and use a number of different scripting languages to achieve the desired effects and tools.  
    4. Create custom tools to facilitate a production scenario. 

    Alongside the class time and your project work, you will be provided with extra learning material, videos and tasks to help you improve your skills.  Work at your own pace spending roughly 4 hours a week on these. 

    All courses in this programme include an assessment of professionalism. Professionalism includes your active engagement in class activities, your ability to communicate with your peers and tutor, how you work in a team and more importantly how you manage your self.

    Usually we cover one session per week. Note this course content and schedule, may be adjusted as we understand more about our needs as a group of learners. 

  •  

    Continue to work on your in class work from last session. For this session we’re going to be introduced to debugging.

    Debugging Python:

    This is a somewhat advanced skill but has the potential to get you out of a tight spot in the future.

    Debugging is a great and irreplaceable tool-set for any developer to have. So, what is it?

    It is the ability to stop your programs at a given point, inspect the variables, change them, examine the call-stack (which function called which) and step through the code, one line at a time. Debugging is a last resort, when critical thinking cannot resolve the bug. But frequently, it’s more effective than putting print statements everywhere.

    So, we can run our programs directly, using Python like this and specifying pdb. This tells python to execute the script with the given module, “pdb” in our case. PDB stands for Python DeBegger.

    python -m pdb /path/to/script.py

    Now, if we tell Python to use the module “pdb”: let’s try this on a program we write to have an error.

    MY_LIST = ['odin', 'dva', 'tree']

    def cause_error(a_list):
       # this will raise an IndexError
       sliced = a_list[4]
       return sliced

    def main():
       fourth = cause_error(MY_LIST)
       print fourth

    main()    

    Then let’s run this with pdb.

    C:\Python27>python.exe -m pdb D:\1_DEV\NMIT_Project\skeleton\SwedishChef\IndexError.py

    The first thing we see is an interactive prompt. PDB will prompt us before doing anything.

    > d:\1_dev\nmit_project\skeleton\swedishchef\indexerror.py(1)<module>()
    -> MY_LIST = ['odin', 'dva', 'tree']
    (Pdb)

    This is an interactive python prompt, except -- we are currently sitting on the first line of the program!

    All your usual python commands will work, but PDB provides us with an extra set of commands.

    The first thing to know is that -- if you ever hit “Enter” on a blank line in PDB, it will re-run the last command you used, for convenience. We’re going to do this with the short-hand commands, but PDB will understand both “c” and “continue”. We’ll get back to a list of commands after.

    • So first let’s type in “c” for continue and hit enter: then we should see a traceback as our error is hit. Python will say “Running cont will restart the program”.

    • Next type in “l” (lower case L) to look at where we are in the code.

    • We can see the error happened on line 5 (in my case) so let’s type in “b 5” which means breakpoint on line 5

    • Run “c” to restart the program, and hit Enter a second time to run it up to our breakpoint

    • Run “j 6” to jump to the next line, skipping our errored line

    • Run “sliced = ‘test’ “

    • Run “c” to run the program through to completion

    • Finally, press Control+C co close and terminate python.

    Did you see what we did there? We told the program to stop at the line we knew would error with a breakpoint, we jumped past the error, and then defined our variable differently, in order to continue the program through to completion. We modified it as it ran.

    If you are interested in PDB, work through this tutorial, and be sure to examine or copy the table of commands at the end. This is an incredibly powerful skillset that will help you as a developer. (and I speak from experience, when I say that most developers and technical artists in our industry don’t even know how to debug!)

    https://www.digitalocean.com/community/tutorials/how-to-use-the-python-debugger

    There is another way to stop programs anywhere you like when running python normally without arguments:

    import pdb 
    pdb.set_trace()

    This works similarly and you don’t need to specify “-m pdb”. Python will run the program normally until it reaches set_trace() and then will stop at that point and prompt you.

    There is one catch -- PDB can only be used when we have access to an interactive prompt, which means not Maya or Nuke (in GUI mode) but only in an interactive python session.

    There are more advanced remote debugging tools available, (Pydev) which can be used through special applications, but we will get to that another year. If you can master PDB then you’ll be better prepared to handle any other debugging tools in the future.

    Well done:

    You’ve completed 506. Next year we have some exciting things lined up, much more in-depth on application APIs, more advanced python, IDEs, and version control. (Since after all, “you can’t have coffee without the cup”). Maybe we’ll even get to GUIs, creating buttons that do things.

    However I want to stress that if you have an appetite for learning, for teaching yourself things new things, this will really help you excel in this fast moving industry. So if you can, after this course is done -- pick up some tutorials, or a book that you're interested in, and work through it. Commit to a little bit every day. Little by little adds up before long.