Mouse issue!

# first you have to see if its on screen
if base.mouseWatcherNode.hasMouse():
    # then you have to get it and only then get its X!
    base.mouseWatcherNode.getMouse().getX() 

Where did you get that snippet? If its from the manual it might need to be tested and changed.