How do I make a script that selcts "X" number...

Hi,

I just want to know how do I do a script that selects any node number, and when I add more nodes I don’t have to modify the script. I’m a complete beginner to scripting.

Thank you.

I’m not sure what you’re asking, could you rephrase that?

How do I make a script, for artificial intelligence, that is used for a bot to follow path nodes,
and it will automatically follow the nodes, without changing the script, no matter which is the quantity of nodes.

I don’t know if that would be possible without a “from magic import *” function. What you’re asking is very complicated.

…ahem.

It’s actually not something that requires an import from the almighty magic module. (we need to save those calls for something a little bit harder) :smiley:

@B3D00

I’m not going to write the script for you, but I will give you a start and a few pointers:


cont = GameLogic.getCurrentController()
own = cont.getOwner()

object_list = GameLogic.getCurrentScene().getObjectList()

nodeNames = []
for object in object_list:
    if object.getName()[:6] == "OBNode":
        nodeNames.append(object.getName())

So, “nodeNames” holds the list of all object names in the scene that start out with “OBNode”. With a bit more logic (and some effort on your part), you can create a process that feeds one node name after another from this list, into a “track to” actuator’s “setObject()” function.

Then all you need to do in order to spawn more nodes (that will register), is to duplicate from the object named “Node” (because blender will automatically name them Node.001, Node.002…and so on).

Get it? If yes, good for you. If no, you need to start with something a little more basic than this particular task.

Good Luck.

great code, i still dont understand how to use slices.Can you plz tell me?

Wow, that’s great, Social. I didn’t know that kind of option existed. This is good, the magic module always overtaxes my processor, especially when it’s not in “more magic” mode.

still dont understand how to use slices.Can you plz tell me?

http://www.swaroopch.com/byteofpython/

Thanks alot, Social.