User Manual: Piapia Language Introduction
- 1 Piapia Language
- 2 Value Types
- 3 Variable
- 4 Function
- 5 Parameter Passing In Function Callings
The trigger system is an important feature added to version 1.50. To use the trigger system, some programming knowledge is needed.
The programming language used in phyard builder is called piapia language. In principle, the language is very like other popular languages, such as c, basic, python, lua, ..., etc. The difference is piapia language programming is achieved by using mouse mostly. There is no compiler for piapia language. You, the designer, is the compiler.
The main features of piapia language:
- functions can have multiple output parameters. (like python and lua)
- all variables are strong type, which means you can't assign a boolean value to a number varible. (like c and basic, but more restricted than them)
- only one number value type, no interger, float, double, byte, ..., etc. All number values are double float. (like lua)
- no pointer and reference variables. (like basic)
- the function and parameter names are not important
- programming is achieved most by using mouse.
- visual programing.
Currently, there are 11 core value types in piapia language: Boolean, Number, String, Collision Category, Array, Module, Sound, ByteArray, ByteArrayStream, MultiPlayerInstanceDefine, and MultiPlayerInstanceChannelDefine. Each of them can be assigned a specific type of value. You can also create custom types.
A Boolean value can only be assigned either TRUE or FALSE. It is most often used for conditional statements.
Example: local[0:"lose?"] = true
A number value stores any numerical value within a specific range. The value range of float number values is from -1.79e+308 to 1.79e+308. For integer number values, the value range is from -2,147,483,648 to 2,147,483,647
Example: local[1:"answer"} = 42
A string value is any piece of text.
Example: local[2:"aText"] = "Hello World"
An entity value stores the ID of any entity (shape or trigger) in the design.
Example: local[3:"anEntity"] = Entity#4
A Collision Category (CCat) value stores the ID of any Collision Category.
Example: local[4:"aCCat"] = CCat#6
Main article: Array
An array stores any number of any type of value. It is essentially a container of many values. The types can differ between the array's elements. An array can store another array within itself. The first value of an array is the 0th element; the second is the 1st element; the third is the 2nd element, and so on.
Sound variables are used for storing sound, but right now they are useless. There is no way to assign them currently (except the Type Common =, but that only world with null anyway)
Custom types are basically anything you want. You can define them in the function editing window, which is the button at the top with fff on it. You can initialize these variables with the Global > Type Common > New API, or write your own custom function to initialize them.
It is recommended that you use Packages for custom functions related to each custom type.
Variable is used to store values, temporarily or permanently. You can change the value of a variable at runtime.
(deprecated in v1.60, use CTRL+SHIFT+K, or Command+Shift+K for Man users, to convert to global variables)
Register variables are some predefined variables. They have no names. There were 16 variable instances for each value type. Register variables is for designer to fast implement an idea without bothering creating custom variables.
Register variables are global variables.
Custom Global Variable
User defined global variables with names. They can be accessed in all event handlers.
Custom Local Variable
User defined local variables with names. They are created in one event handler and can be accessed in only this event handler.
Input variables are the input parameters of the caller function.
For functions with predefined prototypes, such as event handlers, input variables are not customizable. For custom functions, input variables are customizable.
Input variables are local variables.
Output variables are the output parameters of the caller function.
For functions with predefined prototypes, such as event handlers, output variables are not customizable. For custom functions, output variables are customizable.
Output variables are local variables.
Entity Custom Property Variable
Entity custom property variables are user defined variables for every entity in world.
When playing a design, all entities will have a total set entity custom property variables. Many variables may be a waste of memory. But on modern PCs and mobile phones, this is not a big problem.
if Custom Entity Properties are entities themselves, you can't select them in the entity side of the variable like "Input  The Entity" "Property  Other Entity" "Property  Infected" (same thing probably happens in custom type classes which are also that type). This is because the code snippet window is too small to accommodate this.
Generally, a function is composed with 3 parts: input parameters, output parameters and a function calling sequence. The function calling sequence is also called function body.
A function can be called by other functions (in fact, self can also call self) as a function calling.
Parameters of a function is a value define, which indicates what value types should be passed in when this function is called as a function calling in other functions.
We call two functions have a same prototype if their parameters, both input and output defines are identical.
There are 3 function types in piapia language: Core API Function, Predefine Prototype Function and Custom Function
Core API Function
Core API functions are the functions provided natively. The function prototype and function body of a core API are both predefined.
Prototype Predefined Function
The function prototype is predefined but the function body is custom defined. Condition, Action and Event Handler entities all can be view as prototype predefined functions.
The function prototype and function body are both custom defined.
Parameter Passing In Function Callings
In Piapia language, parameter passings are more like Java. It is different with c/c++.
When using the assign APIs, only Numbers and Booleans are exactly value-copied. For other non-primitive types, it just copies the value references (or pointers).
For example, after calling "entityB = entityA", entityB and entityA are exactly the same entity. Calling "SetVisible (entityB, false)" and calling "SetVisible (entityB, false)" are totally same in effect.
For Strings, it also copies the reference. But one thing to note, "stringA + stringB" will return a new string, it is neither stringA nor stringB.