Reputation: 23
This is my first time asking a question on Stack Overflow so I apologize in advance if my question is too vague or if not enough information is provided.
Basically the problem I am having is that my code will not run due to a TypeError.
Here is the exact message:
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 101 4.0\src\debug\tserver\_sandbox.py", line 61, in <module>
File "C:\pygamehelper.py", line 62, in mainLoop
File "C:\Program Files (x86)\Wing IDE 101 4.0\src\debug\tserver\_sandbox.py", line 54, in draw
TypeError: integer argument expected, got float
So I think that the error is occurring due to the tuple associated with pos being converted to a vector using the vec2d method, and then being passed as an argument (as a float) to the draw.circle method in line 54, where an int is being expected. This is how it was done in the tutorial that I am following however, and his code is identical and executed without problems.
Could it possibly be due to him using a different version of Python, or PyGame, or is there something wrong with my code?
Thanks in advance for your help.
from pygamehelper import *
from pygame import *
from pygame.locals import *
from vec2d import *
from math import e, pi, cos, sin, sqrt
from random import uniform
class Agents:
def __init__(self):
self.pos = vec2d(0, 0)
self.target = vec2d(0, 0)
class Starter(PygameHelper):
def __init__(self):
self.w, self.h = 800, 600
PygameHelper.__init__(self, size=(self.w, self.h), fill=((255,255,255)))
self.agents = []
for i in range(10):
a = Agents()
a.pos = vec2d(uniform(0, self.w), uniform(0, self.h))
a.target = vec2d(uniform(0, self.w), uniform(0, self.h))
self.agents.append(a)
def update(self):
for a in self.agents:
dir = a.target - a.pos
dir.length = 5
a.pos = a.pos + dir
def keyUp(self, key):
pass
def mouseUp(self, button, pos):
for a in self.agents:
a.target = vec2d(pos)
def mouseMotion(self, buttons, pos, rel):
pass
def draw(self):
# clear the screen 40 times / sec so that only 1 char and target
# present on screen at a time
self.screen.fill((255,255,255))
for a in self.agents:
# character
pygame.draw.circle(self.screen, (200, 200, 255), a.pos, 10)
# black character outline
pygame.draw.circle(self.screen, (0, 0, 0), a.pos, 11, 1)
# target
pygame.draw.circle(self.screen, (200, 0, 0), a.target, 20, 1)
s = Starter()
s.mainLoop(40)
Upvotes: 1
Views: 23817
Reputation: 11
It seems that your tuiototouch.py on line 92 is passing a float argument (self.x_mouse). Uinput expects only integers.
I think that the int-conversion could be done under the hood in suinput. So perhaps suinput should make sure that ev_value is integer before it passes it to the uinput-system.
So there are two possible solutions. I could either
or
I'm not sure right away which is better, I'll think about it for a while.
Meanwhile, I think you can fix this by typecasting self.x_mouse to int in tuiototouch.py: int(self.x_mouse).
Upvotes: 1
Reputation: 74645
random.uniform(a,b)
returns a float. use int(random.uniform(a,b))
for an integer.
Upvotes: 1