Python error when trying to destroy an object in Ursina - python
I'm pretty new to coding in python but I have started a small little script. Its a first person shooter and right now I'm working on ammo boxes you can pick up. This is the code:
from ursina import *
from random import uniform
from ursina.shaders import lit_with_shadows_shader
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
Entity.default_shader = lit_with_shadows_shader
player = FirstPersonController(model='cube', color=color.orange, origin_y=-.5, speed=8, position = (-52, 0, 57))
player.collider = BoxCollider(player, Vec3(0,1,0))
player.visible = False
ammo = 10
editor_camera = EditorCamera(enabled=False, ignore_paused=True)
ammoCounter = Text(text= ammo + ammo, position = (-0.4,-0.4), color = color.black)
def update():
ammoCounter.text = ammo
def pause_input(key):
if key == 'tab': # press tab to toggle edit/play mode
editor_camera.position = player.position
editor_camera.rotation = (90,180,0)
editor_camera.y = 50
editor_camera.enabled = not editor_camera.enabled
player.visible =True
player.visible_self = editor_camera.enabled
player.cursor.enabled = not editor_camera.enabled
gun.enabled = not editor_camera.enabled
mouse.locked = not editor_camera.enabled
application.paused = editor_camera.enabled
pause_handler = Entity(ignore_paused=True, input=pause_input)
def input(key):
global ammo
## destroy ammo crates##
if key == 'e':
if mouse.hovered_entity == ammo1:
if distance(player, ammo1) <= 5:
ammo += 10
destroy(ammo1)
if mouse.hovered_entity == ammo2:
if distance(player, ammo2) <= 5:
ammo += 10
destroy(ammo2)
if mouse.hovered_entity == ammo3:
if distance(player, ammo3) <= 5:
ammo += 10
destroy(ammo3)
if mouse.hovered_entity == ammo4:
if distance(player, ammo4) <= 5:
ammo += 10
destroy(ammo4)
if key == 'k':
print (player.position)
print (ammo)
if key=="left mouse down" and ammo > 0:
ammo -= 1
if mouse.hovered_entity and hasattr(mouse.hovered_entity, 'hp'):
mouse.hovered_entity.hp -= 10
mouse.hovered_entity.blink(color.red)
print (ammo)
Audio("gunshot")
if gun.position == (0.45,-0.2,0):
Animation("spark", parent=camera.ui, fps=5, scale=.15, position=(0.28, -0.01), loop=False)
print (ammo)
if gun.position == (0,-0.15,0):
Animation("spark", parent=camera.ui, fps=5, scale=.15, position=(-0.005,0.08,0), loop=False)
print (ammo)
if held_keys["q"]:
gun.position = (0,-0.15,0)
gun.rotation = (0,0,0)
Cursor = False
player.speed = 1
if held_keys["shift"]:
player.speed = 100
else:
gun.position = (0.45,-0.2,0)
gun.rotation = (5,30,0)
player.speed = 250 * time.dt
if held_keys["shift"]:
player.speed = 400 * time.dt
## ammo refill class#
class AmmoR(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', texture = 'ammobox', scale = 1, origin_y=-0.5, collider = "mesh", **kwargs)
## amount of amo refill boxes##
ammo1 = AmmoR()
ammo2 = AmmoR()
ammo3 = AmmoR()
ammo4 = AmmoR()
ammo1.position = (-9,2,53)
ammo2.position = (50,1,21)
ammo3.position = (-17,0,31)
ammo4.position = (15,0,8)
class Enemy(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', scale_y=2, origin_y=-0.5, color=color.light_gray, collider='box', **kwargs)
self.health_bar = Entity(parent=self, y=1.2, model='cube', color=color.red, world_scale=(1.5,.1,.1))
self.max_hp = 100
self.hp = self.max_hp
def update(self):
dist = distance_xz(player.position, self.position)
if dist > 40:
return
self.health_bar.alpha = max(0, self.health_bar.alpha - time.dt)
self.look_at_2d(player.position, 'y')
hit_info = raycast(self.world_position + Vec3(0,1,0), self.forward, 30, ignore=(self,))
if hit_info.entity == player:
if dist > 1:
self.position += self.forward * time.dt * 5
#property
def hp(self):
return self._hp
#hp.setter
def hp(self, value):
self._hp = value
if value <= 0:
destroy(self)
return
self.health_bar.world_scale_x = self.hp / self.max_hp * 1.5
self.health_bar.alpha = 1
## ENEMYS FIRST LEVEL
enemie1 = Enemy()
enemie2 = Enemy()
enemie3 = Enemy()
enemie4 = Enemy()
enemie5 = Enemy()
enemie6 = Enemy()
enemie7 = Enemy()
enemie8 = Enemy()
enemie9 = Enemy()
enemie10 = Enemy()
enemie11 = Enemy()
enemie1.position = (10,0,-2)
enemie2.position = (51.9096, 0, -57.6378)
enemie3.position = (53.7879, 0, -57.4827)
enemie4.position = (53.5366, 0, -39.0536)
enemie5.position = (50,0,-2)
enemie6.position = (50,0,-5)
enemie7.position = (22,0,-20)
enemie8.position = (55,0,-4)
enemie9.position = (15,0,-2)
Sky()
maze=Entity(model="maze", scale=10, texture="BK", color= color.gold,collider="mesh")
gun=Entity(model="colt", parent=camera.ui, scale=0.07, texture='tx', position=(0.45,-0.2,0), rotation=(5,30,0))
app.run()
The AmmoR class is the class for the ammo boxes and ammo1,ammo2,ammo3,and ammo4 are the ammo boxes. When I go to pick up the ammo boxes it works fine but when I try to pick up ammo2 Ursina Crashes giving me this error:
(3 aux display modules not yet loaded.)
:prc(warning): changing default value for ConfigVariable paste-emit-keystrokes from '1' to '0'.
:pnmimage:png(warning): iCCP: known incorrect sRGB profile
read obj at: c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game\models_compressed\maze.obj
read obj at: c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game\models_compressed\colt.obj
info: psd-tools3 not installed
warning: missing texture: 'tx'
screen resolution: (1920, 1080)
os: Windows
development mode: True
application successfully started
info: changed aspect ratio: 1.778 -> 1.778
PS C:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game> c:; cd 'c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game'; & 'C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\python.exe' 'c:\Users\MoerkerkeThomas\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '50586' '--' 'c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game\main game fps.py'
package_folder: C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\ursina
asset_folder: c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game
:prc(warning): Invalid integer value for ConfigVariable win-size: 864.0
:prc(warning): Invalid integer value for ConfigVariable win-size: 1536.0
Known pipe types:
wglGraphicsPipe
(3 aux display modules not yet loaded.)
:prc(warning): changing default value for ConfigVariable paste-emit-keystrokes from '1' to '0'.
:pnmimage:png(warning): iCCP: known incorrect sRGB profile
read obj at: c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game\models_compressed\maze.obj
read obj at: c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game\models_compressed\colt.obj
info: psd-tools3 not installed
warning: missing texture: 'tx'
screen resolution: (1920, 1080)
os: Windows
development mode: True
application successfully started
info: changed aspect ratio: 1.778 -> 1.778
Assertion failed: !is_empty() at line 1045 of panda/src/pgraph/nodePath.cxx
Traceback (most recent call last):
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\EventManager.py", line 49, in eventLoopTask
self.doEvents()
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\EventManager.py", line 43, in doEvents
processFunc(dequeueFunc())
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\EventManager.py", line 99, in processEvent
messenger.send(eventName, paramList)
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\Messenger.py", line 337, in send
self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\Messenger.py", line 422, in __dispatch
result = method (*(extraArgs + sentArgs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\ursina\main.py", line 176, in input
__main__.input(key)
File "c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game\main game fps.py", line 52, in input
if distance(player, ammo4) <= 5:
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\ursina\ursinamath.py", line 24, in distance
if hasattr(b, 'position'): b = b.position
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\ursina\entity.py", line 466, in position
return Vec3(*self.getPos())
^^^^^^^^^^^^^
AssertionError: !is_empty() at line 1045 of panda/src/pgraph/nodePath.cxx
:task(error): Exception occurred in PythonTask eventManager
Traceback (most recent call last):
File "c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game\main game fps.py", line 197, in <module>
app.run()
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\ursina\main.py", line 237, in run
super().run()
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\ShowBase.py", line 3330, in run
self.taskMgr.run()
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\task\Task.py", line 553, in run
self.step()
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\task\Task.py", line 504, in step
self.mgr.poll()
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\EventManager.py", line 49, in eventLoopTask
self.doEvents()
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\EventManager.py", line 43, in doEvents
processFunc(dequeueFunc())
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\EventManager.py", line 99, in processEvent
messenger.send(eventName, paramList)
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\Messenger.py", line 337, in send
self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\direct\showbase\Messenger.py", line 422, in __dispatch
result = method (*(extraArgs + sentArgs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\ursina\main.py", line 176, in input
__main__.input(key)
File "c:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game\main game fps.py", line 52, in input
if distance(player, ammo4) <= 5:
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\ursina\ursinamath.py", line 24, in distance
if hasattr(b, 'position'): b = b.position
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\MoerkerkeThomas\AppData\Local\Programs\Python\Python311\Lib\site-packages\ursina\entity.py", line 466, in position
return Vec3(*self.getPos())
^^^^^^^^^^^^^
AssertionError: !is_empty() at line 1045 of panda/src/pgraph/nodePath.cxx
PS C:\Users\MoerkerkeThomas\Desktop\Python stuff\RIP URSINA SHIT\fps game>
I have tried changing the the if function to be structured differently but I think the statement is correct. The only thing I could think of being the issue is the distance between objects variable.
Related
I have this error : raise turtle.Terminator
I hope it run and do not stop. I'm making Conway's Game of Life, if my code look stupid, please help me, I'm only 11. I use the details from wiki, if it's wrong , please tell me. Thankyou! import turtle,random START_POSITION=[] def ReStart(): global START_POSITION #START_POSITION.clear() y=500 x=-500 for i in range(1,26): for a in range(1,26): START_POSITION.append(eval(f"({x},{y})")) x+=20 x=(0-300) y-=20 return True ReStart() screen=turtle.Screen() class Cell: def __init__(self): self.cells=[] self.make_body() self.a() self.Alive(screen) def make_body(self): global START_POSITION for i in START_POSITION: seg=turtle.Turtle(shape="square") seg.color("White") seg.penup() seg.goto(i[0],i[1]) self.cells.append(seg) The error saids: Traceback (most recent call last): File "C:/Users/****/Desktop/寫程式/the life game.py", line 145, in <module> cell=Cell() File "C:/Users/****/Desktop/寫程式/the life game.py", line 20, in __init__ self.make_body() File "C:/Users/****/Desktop/寫程式/the life game.py", line 29, in make_body seg.goto(i[0],i[1]) File "C:\Users\****\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1777, in goto self._goto(Vec2D(x, y)) File "C:\Users\****\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 3180, in _goto self._update() File "C:\Users\****\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 2661, in _update self._update_data() File "C:\Users\****\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 2647, in _update_data self.screen._incrementudc() File "C:\Users\****\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1293, in _incrementudc raise Terminator turtle.Terminator I'm totally stuck on this,please help me.
I've reworked your code fragment into what I believe you are trying to do. Avoid eval as it can cause endless problems. Your use of global in this context isn't valid. See if this works for you: from turtle import Screen, Turtle class Body: def __init__(self, positions): self.cells = [] self.make_body(positions) # self.a() # self.Alive(screen) def make_body(self, positions): for position in positions: cell = Turtle(shape='square') cell.fillcolor('white') cell.penup() cell.goto(position) self.cells.append(cell) def restart(): start_positions.clear() y = 250 for _ in range(25): x = -250 for _ in range(25): start_positions.append((x, y)) x += 20 y -= 20 start_positions = [] screen = Screen() screen.setup(550, 550) screen.bgcolor('black') screen.tracer(False) restart() my_body = Body(start_positions) screen.tracer(True) screen.exitonclick() Since I've turned off tracer() for speed, call screen.update() whenever you're ready for the user to see the most recent changes.
The monitor don't work with digital signal processing
I make a ‘photoplethysmograph’ with Raspberry pi(CM3+) and Maxim sensor(max30102). I connect between Raspberry pi and Maxim sensor by I2C. I write python program. I want to display ‘photoplethysmograpy’ in canvas. First, I am success to display that, but noise appear.(program0) Second, I try to use digital signal processing for removing noise. sampling frequency: 100Hz band pass filter :0.1Hz : 10Hz I write program with band pass filter(progmam1) But, the following error message appear and the program don't move. I want to improve program1. What should I do? error message: /usr/lib/python3/dist-packages/scipy/signal/signaltools.py:1344: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. out = out_full[ind] Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/home/pi/exercize/r210210.py", line 62, in sensor self.add_point0(self.l0,y0_digital/2000) File "/home/pi/exercize/r210210.py", line 80, in add_point0 self.c0.coords(line, *coords) File "/usr/lib/python3.7/tkinter/__init__.py", line 2469, in coords self.tk.call((self._w, 'coords') + args))] _tkinter.TclError: bad screen distance "[1.50422694e-04 1.51988575e-02 1.51988575e-02 2.08" program: import tkinter as tk import threading import time import max30102 import scipy.signal as signal class Test(): def __init__(self,master): self.master = master self.master.geometry("800x600") self.frame = tk.Frame(self.master) self.flag = True self.c0 = tk.Canvas(self.frame, bg="white", widt=760, height=160) self.c0.grid(row=0,column=0) self.c1 = tk.Canvas(self.frame, bg="white", widt=760, height=160) self.c1.grid(row=1,column=0) self.buttonB = tk.Button(self.frame, text="start",command=self.measure) self.buttonB.grid(row=2,column=0) self.l0 = self.c0.create_line(0,80,0,80,fill="blue") self.l1 = self.c1.create_line(0,80,0,80,fill="blue") self.l2 = self.c0.create_line(0,80,0,80,fill="red") self.frame.grid() def measure(self): th0 = threading.Thread(target=self.sensor) if self.buttonB['text'] == "start": self.buttonB['text'] = "stop" self.flag = True th0.start() else: self.buttonB['text'] = "start" self.flag = False def sensor(self): m = max30102.MAX30102() a,b = signal.buttord([0.002,0.2],[0.001,0.3],3,40) y0 = [] y1 = [] while self.flag: red, ir = m.read_fifo() print('RED'+str(red)) print('IR'+str(ir)) #self.add_point0(self.l0, (red/2000)) #self.add_point1(self.l1, (ir/2000)) y0.append(red) y1.append(ir) if len(y0) >= 100: y0_digital = signal.lfilter(b,a,y0) y1_digital = signal.lfilter(b,a,y1) self.add_point0(self.l0,y0_digital/2000) self.add_point1(self.l1.y1_digital/2000) self.c0.xview_moveto(1.0) self.c1.xview_moveto(1.0) y0.pop(0) y1.pop(0) time.sleep(0.01) m.shutdown() def add_point0(self, line, y): coords = self.c0.coords(line) x = coords[-2] + 1 coords.append(x) coords.append(y) coords = coords[-1500:] self.c0.coords(line, *coords) self.c0.configure(scrollregion=self.c0.bbox("all")) def add_point1(self, line, y): coords = self.c1.coords(line) x = coords[-2] + 1 coords.append(x) coords.append(y) coords = coords[-1600:] self.c1.coords(line, *coords) self.c1.configure(scrollregion=self.c1.bbox("all")) def main(): root = tk.Tk() app = Test(root) root.mainloop() if __name__ == '__main__': main()
My define statement will only run once
After my code prints one dot on the screen it doesn't run again. This is what it tells me in the terminal after I close the turtle screen: Traceback (most recent call last): File "/Users/Benjamin/Desktop/Space Digital Scene.py", line 33, in <module> star(size, x, y, color) File "/Users/Benjamin/Desktop/Space Digital Scene.py", line 12, in star drawer.begin_fill() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/turtle.py", line 3322, in begin_fill self._fillitem = self.screen._createpoly() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/turtle.py", line 497, in _createpoly return self.cv.create_polygon((0, 0, 0, 0, 0, 0), fill="", outline="") File "<string>", line 1, in create_polygon File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 2492, in create_polygon return self._create('polygon', args, kw) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 2474, in _create *(args + self._options(cnf, kw)))) _tkinter.TclError: invalid command name ".!canvas" My code is import turtle import random def star(size, X, Y, color): drawer.goto(X, Y) drawer.color(color) drawer.begin_fill() drawer.circle(size) drawer.end_fill() hex = ["blue","red","yellow","white"] screen = turtle.Screen() turtle.bgcolor("black") drawer = turtle.Turtle() drawer.speed("fastest") x = random.randint(-300,301) y = random.randint(-300,301) color = random.choice(hex) size = random.randint(1,6) a = 1 b = 100 while True: if a <= b: star(size, x, y, color) drawer.hideturtle() a + 1 continue else: break screen.mainloop()
You have to assign the new a or use a += 1 and also move some lines inside the while loop to execute them each time: while True: if a <= b: x = random.randint(-300, 301) y = random.randint(-300, 301) star(size, x, y, color) drawer.hideturtle() a += 1 continue else: break screen.mainloop()
Nanpy Servo Control
*Nanpy allows for a Raspi to have an Arduino slave through python Right now I'm having extreme difficulty in using the nanpy Servo package, and I cant get it to run correctly. I'm using it to make a robot that is wirelessly controlled from a computer, this is what I have for code: from nanpy import (ArduinoApi, SerialManager) import pygame from nanpy import Servo import time pygame.init() a=0 d=0 window = pygame.display.set_mode((800,600)) pygame.display.set_caption("Console") try : connection = SerialManager() ard = ArduinoApi(connection = connection) run = True except: print("Connection Failed!") servoA = Servo(2) servoD = Servo(4) while run : for event in pygame.event.get(): keys = pygame.key.get_pressed() # if (event.type==pygame.KEYDOWN): if keys[pygame.K_s] and keys[pygame.K_a]: a=a-1 servoA.write(a) elif keys[pygame.K_s] and keys[pygame.K_d]: d=d-1 servoD.write(d) elif keys[pygame.K_w]: a=a+1 d=d+1 servoD.write(d) servoA.write(a) elif keys[pygame.K_s]: a=a-1 d=d-1 servoD.write(d) servoA.write(a) elif keys[pygame.K_d]: d=d+1 servoD.write(d) elif keys[pygame.K_a]: a=a+1 servoA.write(a) elif keys[pygame.K_t]: run=False pygame.quit() This is the error the python shell throws: Traceback (most recent call last): File "/home/pi/Desktop/nanpy/RobotCode.py", line 28, in <module> servoA = Servo(2) File "/usr/local/lib/python3.4/dist-packages/nanpy-0.9.6-py3.4.egg/nanpy/servo.py", line 9, in __init__ self.id = self.call('new', pin) File "/usr/local/lib/python3.4/dist-packages/nanpy-0.9.6-py3.4.egg/nanpy/arduinoboard.py", line 150, in call return _call(self.namespace, self.id, args, self.connection) File "/usr/local/lib/python3.4/dist-packages/nanpy-0.9.6-py3.4.egg/nanpy/arduinoboard.py", line 47, in _call ret = return_value(connection) File "/usr/local/lib/python3.4/dist-packages/nanpy-0.9.6-py3.4.egg/nanpy/arduinoboard.py", line 18, in return_value return serial_manager.readline().replace('\r\n', '') File "/usr/local/lib/python3.4/dist-packages/nanpy-0.9.6-py3.4.egg/nanpy/serialmanager.py", line 101, in readline raise SerialManagerError('Serial timeout!') nanpy.serialmanager.SerialManagerError: Serial timeout! How can I fix this, and/or what am I doing wrong?
You need to specify the port of the Arduino. So could you try: connection = SerialManager(device='/dev/ttyACM0') or whatever port you are using.
update the configuration file to use the servo and upload it to arduino using the IDE then run this program. you can find the cfg.h file in nanpy-firmware/nanpy folder.
"pygame.error: display Surface quit" while loading
So I'm making a game to test my programming skills and I'm trying to use pygame but when i try and load a level map it says the surface has quit. I have no idea why. This is the load code: def load(self): print(os.listdir()) file = input('>>> file name = ') try: self.Dir = os.getcwd() path = os.path.join(self.Dir, "maps", file) data = pickle.load(open(path, 'rb')) except OSError as error: print('Not file ', path) print(error) else: self.grid = data[0] self.blocks = data[1] Thanks in advance EDIT: this is the trace back Traceback (most recent call last): File "F:\PROGRAMS\snow\mapmaker_v2.py", line 169, in <module> a.loop() File "F:\PROGRAMS\snow\senpy.py", line 95, in loop self.blocks.draw(self.screen) File "F:\BMDSIT\Portable Python 3.2.5.1\App\lib\site-packages\pygame\sprite.py", line 475, in draw self.spritedict[spr] = surface_blit(spr.image, spr.rect) pygame.error: display Surface quit EDIT 2: This is the loop code where it happens: (The load command is in the self.keyboard() function.) def loop(self): print('looping') for event in pygame.event.get(): if event.type == pygame.QUIT: print('quiting :(') pygame.display.quit() quit('User quit') self.screen.fill((237, 237, 237)) self.keys = pygame.key.get_pressed() self.mos = pygame.mouse.get_pressed() self.mouse() self.keyboard() #screen.blit(player,player.pos) self.blocks.draw(self.screen) self.extraLoop() pygame.display.flip() print('done looping')
You can't pickle a Surface object. If you want to pickle an object that contains a Surface, remove it before saving it to disk; and store the name of the image file or a string representation of the Surface instead in the object.