Freepie Script only partially loading

Official forum for open source FreePIE discussion and development.
Post Reply
MeteorFalling2
One Eyed Hopeful
Posts: 42
Joined: Thu Dec 08, 2016 10:23 pm

Freepie Script only partially loading

Post by MeteorFalling2 »

Hello,

I have a problem with my script loading in Freepie. Sometimes it loads the entire script, but other times it loads only a part of it. For example, it will ignore diagnostic.watch(x) commands and if statements.

As my script became more complex, the odds of loading the entire script has become less and less. Right now, I am lucky if my script loads my 'def update():' and other if statements. Out of 30 tries, it will load maybe once.

I am new to programming so I don't quite know what would cause my problem as it was working fine until I added more button mappings and the like. Does anyone know why this is happening. And if so how can I fix it?

Here is my script:

Code: Select all

import thread, time


def update():
	diagnostics.watch(wiimote[0].ahrs.yaw)
	diagnostics.watch(wiimote[0].ahrs.pitch)
	diagnostics.watch(wiimote[0].ahrs.roll)
	diagnostics.watch(wiimote[0].motionplus.yaw_down*0.1)
	diagnostics.watch(wiimote[0].motionplus.pitch_left*0.1)
	yaw = filters.deadband((wiimote[0].motionplus.yaw_down), 0.15) 
	pitch = filters.deadband((wiimote[0].motionplus.pitch_left), 0.15) 

	if wiimote[0].buttons.button_down(WiimoteButtons.A) or wiimote[0].buttons.button_down(WiimoteButtons.Home): 
		mouse.deltaX = yaw/-9
		mouse.deltaY = pitch/9
		
def togglerun():
	global movex
	global movex2
	global movey
	global movey2
	diagnostics.watch(wiimote[0].nunchuck.acceleration.x)
	diagnostics.watch(wiimote[0].nunchuck.acceleration.y)
	diagnostics.watch(movex)
	diagnostics.watch(movex2)
	diagnostics.watch(movey)
	diagnostics.watch(movey2)
 
	if movex == 0:
		if (wiimote[0].nunchuck.acceleration.x >= 7):
			movex = 1
			
	if movex == 1:		
		if filters.stopWatch((wiimote[0].nunchuck.acceleration.x < 9), 600):	
			movex = 0						
	
	if movex2 == 0:	
		if (wiimote[0].nunchuck.acceleration.x <= -6):
			movex2 = 1
			
	if movex2 == 1:	
		if filters.stopWatch((wiimote[0].nunchuck.acceleration.x > -6), 600):			
			movex2 = 0
			
	if movey == 0:
		if (wiimote[0].nunchuck.acceleration.y >= 5 ):
			movey = 1
	if movey ==1:
		if filters.stopWatch((wiimote[0].nunchuck.acceleration.y < 9), 600):
			movey = 0
			
	if movey2 == 0:	
		if (wiimote[0].nunchuck.acceleration.y <= -5):
			movey2 = 1
	if movey2 == 1:
		if filters.stopWatch((wiimote[0].nunchuck.acceleration.y > -5), 600):
			movey2 = 0
			
def wiimotebuttons():

	mouse.leftButton = wiimote[0].buttons.button_down(WiimoteButtons.B)
	keyboard.setKey(Key.E, wiimote[0].buttons.button_down(WiimoteButtons.DPadLeft))
	keyboard.setKey(Key.F, wiimote[0].buttons.button_down(WiimoteButtons.DPadUp))
	keyboard.setKey(Key.R, wiimote[0].buttons.button_down(WiimoteButtons.DPadRight))
	keyboard.setKey(Key.X, wiimote[0].buttons.button_down(WiimoteButtons.DPadDown))
	keyboard.setKey(Key.R, wiimote[0].buttons.button_down(WiimoteButtons.Plus))
	keyboard.setKey(Key.X, wiimote[0].buttons.button_down(WiimoteButtons.DPadDown))	
	keyboard.setKey(Key.LeftAlt, wiimote[0].buttons.button_down(WiimoteButtons.Two))
	keyboard.setKey(Key.Q, wiimote[0].buttons.button_down(WiimoteButtons.Home))
	keyboard.setKey(Key.Z, wiimote[0].buttons.button_down(WiimoteButtons.One))
	
	if filters.stopWatch((wiimote[0].buttons.button_down(WiimoteButtons.DPadLeft)), 100):
		keyboard.setKeyDown(Key.D1)
		
	if not wiimote[0].buttons.button_down(WiimoteButtons.DPadLeft):
		keyboard.setKeyUp(Key.D1)
		
	if filters.stopWatch((wiimote[0].buttons.button_down(WiimoteButtons.DPadUp)), 100):
		keyboard.setKeyDown(Key.D2)
		
	if not wiimote[0].buttons.button_down(WiimoteButtons.DPadUp):
		keyboard.setKeyUp(Key.D2)
		
	if filters.stopWatch((wiimote[0].buttons.button_down(WiimoteButtons.DPadRight)), 100):
		keyboard.setKeyDown(Key.D3)
		
	if not wiimote[0].buttons.button_down(WiimoteButtons.DPadRight):
		keyboard.setKeyUp(Key.D3)
		
	if filters.stopWatch((wiimote[0].buttons.button_down(WiimoteButtons.DPadDown)), 100):
		keyboard.setKeyDown(Key.D4)
		
	if not wiimote[0].buttons.button_down(WiimoteButtons.DPadDown): 
		keyboard.setKeyUp(Key.D4)
		
	if filters.stopWatch((wiimote[0].buttons.button_down(WiimoteButtons.Minus)), 100):
		keyboard.setKeyDown(Key.D5)
		
	if not wiimote[0].buttons.button_down(WiimoteButtons.Minus):
		keyboard.setKeyUp(Key.D5)
	
def nunchuckbuttons():
	global doubleclick
	global event
	global statuschange
	global timer
	diagnostics.watch(event)
	diagnostics.watch(statuschange)
	diagnostics.watch(doubleclick)
	
	mouse.rightButton = wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.Z)
	
	if filters.stopWatch((wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.C)), 300):
		statuschange = 1
		
	elif not wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.C):
		statuschange = 0
		
	if statuschange == 0:
		keyboard.setKeyUp(Key.LeftShift)
		keyboard.setKeyUp(Key.LeftControl)		
		
	if statuschange == 1:
		if wiimote[0].nunchuck.stick.y > 50:
			keyboard.setKeyDown(Key.LeftShift)
		else:
			keyboard.setKeyUp(Key.LeftShift)
			
		keyboard.setKey(Key.LeftControl, wiimote[0].nunchuck.stick.y < -50)
		

	if wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.C) and (doubleclick == 0):
		doubleclick = 1
		event = 1
		
	if not wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.C) and (doubleclick == 1):
		event = 0
	
	if filters.stopWatch((doubleclick == 1), 200):
		doubleclick = 0
		
	if (doubleclick == 1) and (event == 0):
		if wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.C):
			keyboard.setKeyDown(Key.Space)
			keyboard.setKeyUp(Key.Space)
			
	
def runToggle():
	global movex
	global movex2
	global movey
	global movey2
	global moveOn
	diagnostics.watch(moveOn)
	diagnostics.watch(keyboard.getKeyDown(Key.W))
	diagnostics.watch(keyboard.getKeyDown(Key.A))
	diagnostics.watch(keyboard.getKeyDown(Key.S))
	diagnostics.watch(keyboard.getKeyDown(Key.D))

	if moveOn == 0:
		keyboard.setKeyUp(Key.W)
		keyboard.setKeyUp(Key.A)
		keyboard.setKeyUp(Key.S)
		keyboard.setKeyUp(Key.D)
		
		if (movex == 1) or (movex2 == 1) or (movey == 1) or (movey2 == 1):
			moveOn = 1
			
	if moveOn == 1:	
		keyboard.setKey(Key.W, wiimote[0].nunchuck.stick.y >= 30)
		keyboard.setKey(Key.S, wiimote[0].nunchuck.stick.y <= -30)
		keyboard.setKey(Key.D, wiimote[0].nunchuck.stick.x >= 30)
		keyboard.setKey(Key.A, wiimote[0].nunchuck.stick.x <= -30)
		
		if (movex == 0) and (movex2 == 0) and (movey == 0) and (movey2 == 0):
			moveOn = 0
			  
if starting:
			
	system.setThreadTiming(TimingTypes.HighresSystemTimer)
	system.threadExecutionInterval = 2
	wiimote[0].motionplus.update += update
	wiimote[0].buttons.update += wiimotebuttons
	wiimote[0].nunchuck.update += togglerun
	wiimote[0].nunchuck.update += runToggle
	wiimote[0].nunchuck.update += nunchuckbuttons
	statuschange = 0
	doubleclick = 0
	movex = 0
	movex2 = 0
	movey = 0
	movey2 = 0
	moveOn = 0
	multiply = 20
	doubleclick = 0
	event = 0
	timer = 0
	
	wiimote[0].enable(WiimoteCapabilities.MotionPlus | WiimoteCapabilities.Extension)
	 
MeteorFalling2
One Eyed Hopeful
Posts: 42
Joined: Thu Dec 08, 2016 10:23 pm

Re: Freepie Script only partially loading

Post by MeteorFalling2 »

So I think I found a solution to my problem. I removed all the diagnostics.watch commands from each def statement. My script is now behaving correctly, however, I no longer can watch what is going on. I have to start it and test it in-game to see if it works.

For example my nunchuck has acceleration tied with enabling joystick actions so that I have to run in place for me to move in-game. If I start the script with the nunchuck at the wrong angle, the acceleration values can become distorted, causing my 'if statements' to always be enabled.

Is there anything I can do to show diagnostics, or is it something I need removed from my code to work?
MeteorFalling2
One Eyed Hopeful
Posts: 42
Joined: Thu Dec 08, 2016 10:23 pm

Re: Freepie Script only partially loading

Post by MeteorFalling2 »

Well I thought I solved it. I added some more code, and the problem returned. I understand optimizing code, but the tasks I want to do would utilize all the capabilities of the Wiimote +M and Nunchuck.
Post Reply

Return to “FreePIE”