Learning python – by making a simple text based game

I’ve been trying to learn more python so I can automate day to day tasks. I have been using it in blender to create some simple operators to change multiple bone shapes at once and help speed up other rigging processes, but found myself stumbling when the complexity required goes above a simplistic script. Cue more learning required.

In an attempt to learn more python I’ve started making a small, simple text based adventure game! learningPython.png

Making games is fun and I’ve never made a text based game before and apparently learning happens best when you having fun. Needless to say I’m loving python! My favorite language feature so far is list slicing, and list comprehension.

Initially I had a simple game loop running all in a single file (it was nasty) but was awesome to see how much was being done with so few lines of code. I’ve since extracted functionality and separated the game into different classes that handle their own responsibilities and have shared structure across common entities. In making all these separate files, I’ve learnt ways to import the different modules and how to group them into a common packages. It’s exactly what I was hoping to get from this exercise.

Making a text based game is helping me FOCUS. How to separate functionality and how to think of “when to class” more than anything I’ve made in unity so far. I think it’s because I can’t get distracted and get lost in decisions about making pretty pixels. It’s a frequent trap I find myself in, only realizing where I am after having sunk many hours in doing “not the next most important thing”. Even though I know about the trap, my feet get caught by it 90% of the time, but in this environment I seem to be flying it’s awesome!

So if you wanting to learn python but don’t have and idea for a project that can help you right now, try making a simple text based adventure! It’s fun 😀

Advertisements

Blender Python nulls along a curve

I’ve been trying  to learn python in blender and here’s my first go at scripting something:

To use:

1.make a nurbs curve

2.make 5 nulls/empties

3.select all empties

4.run script


import bpy

selected = bpy.context.selected_objects

count = 0
total = 4
offset = 0.0

for obj in selected:
offset = count/total
bpy.context.scene.objects.active = obj
bpy.ops.object.constraint_add(type='FOLLOW_PATH')
bpy.context.object.constraints["Follow Path"].target = bpy.data.objects["NurbsPath"]
bpy.context.object.constraints["Follow Path"].use_fixed_location = True
bpy.ops.object.location_clear()
bpy.context.object.constraints["Follow Path"].offset_factor = offset
count += 1

curveRigging_01

eyelidSetup

Hoping to make it more generic and dynamic and as a operator.

I tried getting the list.count for the total but it wasn’t returning a decimal number :S so need to find out how to get the count of a selection. list.count()

Also want to make it so that the last object selected is the curve, at the moment it just looks for a curve called NurbsCurve, LAME.

I think it’s a good start for learning python and it’s loads of fun, I’m looking forward to rigging more things with curves.