Page 1 of 1

[beginner] help with first script, syntax, vars, and names

Posted: Wed Sep 23, 2015 8:32 pm
by Moromillas
Hello, I am completely new to both python and freePIE. I just made my first script, and, it works, but I've a few questions about how you use python and freePIE to get things done.

Here's the script in full:

Code: Select all

if starting:
	diagnostics.debug("hello world")
	speech.say("penis")
	lastx = 0

	def print_lastx():
		lastx = mouse.deltaX
		diagnostics.debug(lastx)



if mouse.deltaX != lastx:
	print_lastx()
Now my questions,

Firstly, because the function assigns a new value to lastx, and the var is also used outside of the function, the var needs to be global. To do that, I tried using

Code: Select all

lastx = nil
but python just said: Oh, what's "nil"? So instead of nil, I just gave it a value of 0. But what I really want to do, is say in python; "Ok, I want to reserve a name, as a global var, don't give it a value yet, just reserve it." How do I do that? Is there a special way you do that in python?


Secondly, does freePIE have a more elegant, or better way to check if the value of mouse.deltaX has changed?
Something along the lines of

Code: Select all

if changed(mouse.deltaX):
rather than making and comparing it to vars.


Thanks to you!

Re: [beginner] help with first script, syntax, vars, and nam

Posted: Thu Sep 24, 2015 10:49 am
by CyberVillain
the keyword for null in python is None

Some plugins are event driven, meaning you can do

Code: Select all

def onUpdate():
   diagnostics.watch(android[0].yaw)

if starting:
   android[0].update += onUpdate
Mouse is not one of those plugins how ever

Re: [beginner] help with first script, syntax, vars, and nam

Posted: Thu Sep 24, 2015 11:27 pm
by Moromillas
CyberVillain wrote:the keyword for null in python is None

Some plugins are event driven, meaning you can do

Code: Select all

def onUpdate():
   diagnostics.watch(android[0].yaw)

if starting:
   android[0].update += onUpdate
Mouse is not one of those plugins how ever
Oh, right, so that's some sort of hooking thing yeah? Where you can get the main code to also run a function you want?

So you could do something like:

Code: Select all

def onUpdate():
   #buttons

wiimote.update += onUpdate

If I can't use a hook for the mouse, is comparing it to a global var the best way you think?


Also, what is the android[0].update event exactly? Like, when does it fire? Is it every time there's a change in the android? Or, does it just keep firing every chance it gets?


Also also, I managed to connect a wiimote, but, how do you turn off the LED's on a wiimote in freePIE?

Re: [beginner] help with first script, syntax, vars, and nam

Posted: Sat Sep 26, 2015 3:32 am
by CyberVillain
Yes, its basicly adding the pointer to that function on a stack. Each time the "event" fires each function will be executed

How the trigger happens is different for different input.
In androids case its if a new data package arrive over UDP. We do not check if there are actual change since last package. Its a fair chance there are a chance since you cant hold it stil enough ;)

Currectly only way to detect changes today with mouse and keyboard are to compare.

There are some state helper functions like mouse.getPressed(0) this will only fire each time you hold the button and release and hold again.
In a future release be might add support for the update event

edit: We do not support controlling the LEDs sorry. We need more C++ coders to continue development of wiimote plugin