can't use range() function in a method


I’m making a tank object, which will be run by a single script, which controls all its actuators and does everything neatly within methods. When a tank object is instantiated, it is added to the GameLogic module in a list and can be found by checking its unique ID.

ANYWAY. I’m currently integrating a particle effect into a method called “explode()”, which will make the tank appear to explode. The problem is that the method doesn’t seem to recognise that range() is a function in this method, and not a global variable as it believes. Can you work out what I’m doing wrong?

Thanks for your help.

1/1 credit(s)


classExample.blend (155 KB)

bumpbump. bump.

I took a look at your blend, you’re doing everything right, no clue why it is throwing errors.

I even tried inserting

for i in range(3):
    print i

in the class, and it was getting the same error.

Very strange

There is an issue I’ve encountered within BGE python a few times. It seems builtin is not automatically imported in classes, IIRC. You’ll have to import builtin yourself or you may even have to pass the builtin module as an argument for your class. I don’t recall exactly how I got around it anymore.

ok, I found a solution

take your class definitions and place them into a new .py file

then import that py file in to

from import *

Guess it’s good practice to keep class definitions seperate from scripts that blender runs.

Woohoo!!! Thanks jplur! Your idea worked great! Now check out the mighty awesomage that is my low poly, exploding tank!

Basically, each particle is designed to follow a vector from the centre of the object to each vertex. This way, a round explosion can be created. You can change the mesh to anything you like and see the different explosion effects.

Thanks again for all your help!

1/1 credit(s)


classExample.blend (152 KB)

I’ve come across the same error before, drove me nuts. I couldn’t even import either, because none of the keywords were defined.