cant run taskmanager

i have written a little section of code for my project in order to prototype a bone joint being by the keyboard.the code doesnt have the keyboard part yet but only has the bone bieng controlled by the task module.i dont know how to run the fuction though

control = hand.controlJoint(None,“modelRoot”,“bone1”)
hand.loop(“move”)

global left
left=0

def increment():
left=left+1
return left

def left(task):
control.setP(increment())
return Task.cont

how do i call the actual fuction def left(task)

i tried varous things but it all gave me errors.

i would really aprreciate if anyone could help me here as i need this to work for my school project
thanks

how about
taskMgr.add(left, “turnsomethinglefttask”)
?

the game runs but nothing happens.
the bone is meant to be moving to the left constantly
was there something wrong in the code

i think i found the answer to my own problem,corect if im wrong,the code works but vairable left is not being affected in the left(task) fuction.
how do i actually make the variable ‘left’ be affected by all fuctions as in if the value of left=52 in the increment fuction then i want ‘left’ to be 52 in the left(task) fuction.

i think i have solved that other problem.
the console keeps spitting an error at me saying

“Tried to add a task that was not a task or func”

i have no idea what is going on anymore
here is my code

control = hand.controlJoint(None,"modelRoot","bone1")
hand.loop("move")
left = None

def increment():
    global left
    left=0
    left=left+1
    return left


def left(task):
    control.setP(left)
    return Task.cont

increment()
taskMgr.add(left, "left") 

run()

please some help out
thanks

You can’t have a function and a variable the same name in Python–they step on each other. So your function called “left” is getting confused with the variable called “left”.

David

I have fixed up my code.i have sat at least 2 hours trying to figure out why it is nt working.The bone model is meant to move to the left at intervals of 1 evrey frame.I looked at my code and it seems logical unless im missing something very crucial,heres my entire code.If some one could please give me thier idea on the matter
thanks

import direct.directbase.DirectStart
from direct.task import Task
from direct.actor import Actor


hand= Actor.Actor("models/test_rod",{"move":"models/test"}) 
hand.setPosHprScale(0.045,-0.000,6.758,0.000,0.000,0.000,1.000,1.000,1.000)
hand.reparentTo(render)

camera.setX(-0.0195376984775)
camera.setY(-24.3350944519)
camera.setZ(10.0)
camera.setH(-0.442351669073)
camera.setP(0.0)
camera.setR(0.0)
camera.getChild(0).node().getLens().setNear(1.0)
camera.getChild(0).node().getLens().setFar(1000.0)

camera.getChild(0).node().getLens().setFilmSize(1.000,0.750)
camera.getChild(0).node().getLens().setFocalLength(1.39951908588)
camera.setTag("Metadata","")
camera.reparentTo(render)
base.disableMouse()
base.setBackgroundColor(0.000,0.000,0.000)



control = hand.controlJoint(None,"modelRoot","bone1")
hand.loop("move")
right = None

def increment():
    global right
    right=0
    right=right+1
    return right


def left(task):
    control.setP(right)
    return Task.cont

increment()
taskMgr.add(left, "left") 

run()

Hello David,
I didn’t run your code (don’t have the models anyway), but from what I see your “hand” model will stay in one place. Let me try to explain why.

right = None

def increment():
    global right
    right=0
    right=right+1
    return right


def left(task):
    control.setP(right)
    return Task.cont

increment()
taskMgr.add(left, "left")

run()

I focus on just this part of your code, since it is where you “control” your scene. This is what happens when you run the code, step by step:

First, “None” gets assigned to the variable “right”. Fine.

Next you define a method “increment”. The method is only defined, it isn’t called yet. So nothing happens.

Next you define another method, “left”. It is defined as a Panda3D task, but not yet added to the task managed, so again nothing happens until now.

Now you call “increment( )” once. The method defines a global variable “right”, that means assigning a value to “right” will change the variable not only in local namespace.
Let’s have a closer look at the internals of method “left”:

  1. You assign 0 to the variable “right”. Now “right” has the value “0”. Every time you call the method, no matter what right has been before.
  2. You assign “right + 1” to the varibale “right”. since “right” has been “0” before it is now “1”.
  3. You return the variable “right”. Useless, since the return value is discarded. To use a return value you would have to call the method like this: “foo = increment( )”.
    So, in total, after calling “increment( )” your variable “right” is always 1, no matter how often you call “increment”

Just using “right = 1” would have the same effect.

On to the next line. You add the method “left” to the task manager. This means once the game is running the method “left” will be called by Panda3D once a frame. But it is not yet running.

Last line: you enter the game main loop by calling “run( )”. So from now on the method “left” will be called once a frame.

Ok, what happens from now on? Each frame “left” gets called.
Let’s have a look at the what exactly the method “left” does:
It sets the Pitch § to the value “right”. And “right” is 1. So each frame the pitch of “control” is set to 1 (degree). Pitch is the angle your models “nose” points up or down, if it was an aircraft.

So, no code to move the model sideways/left, only code to set it’s orientation. And the task will always set the same orientation, so it will stay where it is and look in the same direction forever.

Let me suggest some code to replace all of the above lines:

def left(task):
    control.setX( control.getX( ) + 1 )
    return Task.cont

taskMgr.add(left, "left")
run()

Just a warning: This means once a frame the model “control” is translated by 1 sideways. At 60fps this makes a translation of 60 per second. At 600 fps (simple scene, so possible on current hardward) this means 600 per second. To be able to see the movement you should use a smaller value, perhaps 0.02.

Hope this helps to get you started.
enn0x

THANKS VERY MUCH
i have been trying to figure this out for two days now.
you have saved me allot of time.
i never even new that the function control.getP( ) existed.
Thanks again.

No problem. Just two things:

(1) To move left/right you have to use setX( ) and getX( ). X like X-Axis, which is left/right for most Panda3D users. setP( ) and getP( ) are about pitch.

(2) I never used actor.controlJoint( ) before, and I don’t know what it returns. Might be a good idea to check if it is a NodePath. And even if it is I don’t know if it is possible to move a single joint which is part of an Actor sideways. But of course you can try it.

enn0x

panda3d.org/manual/index.php/C … ocedurally

It actually works now,and you can actually make the bone move sideways with control joint as it is a node.
cheers.