表达式规则
任何语言都有使用规则,表达式也不例外。在ProtoPie中规定,可以将文本、数字、图层属性和变量等元素组合在一起建立成表达式。
字面量
在表达式中输入图层属性、数字、文本等元素时,应遵守以下规则。
图层属性
使用图层属性时,在图层名称两侧需要使用半角单引号(`)。为了避免混淆,建议每个图层使用不同的命名。
在(.)号后面输入要使用的图层属性。
了解更多关于图层属性的内容。
![fomula](https://cdn.sanity.io/images/vidqzkll/production/a4cf7b6999972cd8960e30894b17261d8df8815d-1090x70.png)
文本
在文本两侧需要使用半角单引号。
![fomula](https://cdn.sanity.io/images/vidqzkll/production/3ebb3519940904ce44629e6528acd43e5055eb2e-1450x94.png)
文本换行
换行时需要使用\n
![fomula](https://cdn.sanity.io/images/vidqzkll/production/3dbeb98ba0b661ca31f91b410217404f1fd5fc2e-1450x94.png)
数字
只能使用0~9的数字。
![fomula](https://cdn.sanity.io/images/vidqzkll/production/1f5b65b6bbf016659bba1a1aed59b81a7993fd83-1090x70.png)
颜色
需使用#FFFFFF格式的颜色值。
![fomula](https://cdn.sanity.io/images/vidqzkll/production/43932d4c61e3b7596a6db1431f2cf3cbe1bbd63a-1090x70.png)
变量
变量不需要加其他符号,直接输入变量名即可。变量名只能包含拉丁字母、数字和下划线。
了解更多关于变量的内容。
![fomula](https://cdn.sanity.io/images/vidqzkll/production/166bf4d417e555b2d89bdab22c19c9c6faf0f0e2-1090x70.png)
运算
在表达式中可以使用加号(+)、减号(-)、乘号(*)、除号(/)和余数(%)做基本的运算。
运算符号
基本的运算符号有加号(+)、减号(-)、乘号(*)、除号(/)
![fomula](https://cdn.sanity.io/images/vidqzkll/production/83dd91fd2928103c756be82399ad891aa6c68778-1450x94.png)
5
余数符号
整除部分以外余下的部分叫做"余数"。例如5%2 表示 5除以2之后得2,余数是1,所以 5%2 = 1。
![fomula](https://cdn.sanity.io/images/vidqzkll/production/7c158445cebdfc3902730c6c1814598fcda961e8-1450x94.png)
1
组合文本
运算通常适用于数字,但也可以使用加号(+)将两个文本连接。
文本+文本
使用加号(+)连接两个或两个以上的文本。注意文本两侧需要使用半角双引号(")。
![fomula](https://cdn.sanity.io/images/vidqzkll/production/bfcf95ffae45a4bece4b953a7d2da415db2f2721-1450x94.png)
"helloworld"
![fomula](https://cdn.sanity.io/images/vidqzkll/production/31ef00b84bbe053df726518a350cf654084b535a-1450x94.png)
"12"
文本+数字
使用加号(+)连接两个或两个以上的文本和数字,组合成一个新的文本。
![fomula](https://cdn.sanity.io/images/vidqzkll/production/fe27ad177f814da98be602d78a3b8bfee9ae0817-1450x94.png)
"hello1234"