task.time

Hello all, I’m trying to create a simple app that determines how many Clicks per minute you can do using your left and right mouse buttons. Im just using print to display the clicks/minute.So far ive created something that just increases a variable by 1 every click and spits it out in the terminal. I dont know how to divide that variable by how long my task has been running to show your cpm. my code is as foolows so far

from direct.showbase.ShowBase import ShowBase
from direct.showbase import DirectObject
from direct.task import Task

hitcount = 0
 
class MyApp(ShowBase):
 
    def __init__(self):
        ShowBase.__init__(self)
        base.disableMouse()
        
        
 
class Hello(DirectObject.DirectObject):
    
    def __init__(self):
        self.accept('mouse1',self.printHello)
        self.accept('mouse3',self.printHello)
        
    def printHello(task):
        global hitcount
        hitcount += 1
        print hitcount
        
    
h = Hello()

app = MyApp()
app.run()

I don’t know if this is exactly what you need, anyway:

from direct.showbase.ShowBase import ShowBase 
from direct.showbase import DirectObject 
from direct.task import Task 
from direct.gui.OnscreenText import OnscreenText

hitcount = 0 
   
class MyApp(ShowBase): 
  
    def __init__(self): 
        ShowBase.__init__(self) 
        base.disableMouse()
  
class Hello(DirectObject.DirectObject): 
    
    def __init__(self): 
        self.accept('mouse1',self.printHello) 
        self.accept('mouse3',self.printHello)         
        
    def printHello(self): 
        global hitcount 
        hitcount += 1 
        print hitcount 
        
    def cpm( self, task ):
      task.time and \
        cpm.setText(
          str(
            round(
              hitcount / ( task.time / 60 ),
              2 ) ) )
      return task.cont
    
h = Hello() 

app = MyApp() 

cpm = OnscreenText( pos = ( 0, -.2 ), scale = .05, mayChange = True )
app.taskMgr.add( h.cpm, '...' )

app.run() 

Awesome thanks :smiley: I’ll give it a try when I get out of school

Worked great! Thanks :smiley:. Now im tryig to pack it with packpanda – dir but i get a “cannot copy game to C:\Windows\System32\packpanda-TMP” error. im not quite sure what to do to fix this D: ive yet to reinstall panda3d ill give it a shot. any other opinions would be great! :smiley:

:open_mouth:
You’d better work with packp3d. :wink:

Packp3d? I’ve seen it, but what is it exactly? Also I just had to give the packpanda.exe administer powers. It worked :smiley:

It’s (one of) the new deployment tool(s) of Panda.

Aaaaah kk. I’m assuming the console command for it is packp3d --dir x
?

Read the part III of the Manual; the section III.A.1 introduces packp3d.