Documentation on working with Python node and programming
Start
We will use the project made in the previous documentation: First program
Python node allows you to write code in this language and execute the written functions in the program
Create nodes
Create a node On game start and Python
Python node takes 3 parameters: code to execute, arguments as a list, arguments as a dictionary, and returns the list that the function returns
Programming
When you click on the button in the node, a window opens in which you can write code in Python
Only the code that is in the run function will be executed
Functions
Below is a list of all functions that copy the functionality of nodes
Functions:
- decodeHolder(text) -> return decoded value
- exit() -> close project
- getVar(name, global) -> return variable by name and globality
- setVar(name, global, value) -> set value to variable by name and globality
- objectsGroup(group) -> return all objects in group
- random(a, b) -> return random number in [a, b]
- writeText(text) -> write text on console
- displayText(text, x, y) -> display text on scene in x, y
- collision(id, group, append) -> return [True, object ID] if collision else [False, -1]. Append - count contact as a collision
- createObject(name, x, y) -> create object by name in dir objects and place this on x, y
- getObjectIDByName(name) -> return ID of object by name. Name have object which were created on stage before running
- getObjectPos(id) -> return object x, y by ID
- setObjectPos(id, x, y) -> set position for object by ID
- getObjectVar(id, name) -> return variable by object ID and name
- setObjectVar(id, name, value) -> set value to variable by id and name
- jump(id) -> jump for object by ID
- moveObject(id, angle, power) -> create moving vector by angle and power for object ID
- moveObjectWithBraking(id, angle, power, braking) -> create moving vector bu angle, power and braking speed foor object ID
- removeObject(id) -> remove object by ID
- getResultingVector(id) -> returns [x, y] - the resulting all vectors for object by ID
- runAnimation(id, animation) -> starts the animation for the object by ID
- stopAnimation(id) -> sets the animation to the base if it exists, otherwise sets the object's sprite for the object by ID
- mirrorAnimation(id, horizontal, vertical) -> mirrors animations of the object by ID horizontally and vertically, sets True for reflection on this axis
- getMousePos() -> return mouse x, y
- setObjectParameter(id, name, value) -> set object parameter for object by ID
- getObjectParameter(id, name) -> return object parameter for object by ID
- getTimePassed() -> return frame time passed
- getNoiseValue(seed, x, y, octaves, frequency, amplitude, lacunarity, persistence, minValue, maxValue) -> return Perlin noise value on X, Y
- sin(x) -> return sin X
- cos(x) -> return cos X
- tan(x) -> return tan X
- ctg(x) -> return ctg X
- degrees(radians) -> return degrees from radians
- radians(degrees) -> return radians from degrees
- goToScene(scene) -> go to scene by name
- getSceneName() -> return scene name
- playMusic(path) -> play music by path
- stopMusic() -> stop music
- playSound(path) -> play sound by path