跳轉到內容

Pixilang/語言元素

來自華夏公益教科書,自由的教科書

語言元素

[編輯 | 編輯原始碼]

// - 註釋。例如://blah blah blah

/* */ - 多行註釋。例如

/* blah blah blah
blah blah blah */

文字字串

[編輯 | 編輯原始碼]

例如

a = "text string"

當此字串用作某些命令的引數(除 make_pixi 外)時,您可以將變數的數值放入任何字串中。例如

blahblah = 34
video_export_gif( "VIDEO$blahblah.gif" )
//Save video to the VIDEO34.gif

ASCII 碼

[編輯 | 編輯原始碼]

ASCII 碼(最多 4 個符號):'A','B','ABC'... 例如

ascii_code = 'E'

a,b,c,d... 和其他字母符號 - 用於建立您自己的變數。例如 myvar = 4 //將 4 放入變數 "myvar"

數學運算

[編輯 | 編輯原始碼]

-,+,*,/,% - 數學運算。例如:a = b + 4

條件運算

[編輯 | 編輯原始碼]
  • < - 小於
  • > - 大於
  • <= - 小於或等於
  • >= - 大於或等於
  • = - 等於(在 if 運算子之後)
  • != - 不等於

二進位制邏輯運算

[編輯 | 編輯原始碼]
  • ^ - 異或
  • & - 並且
  • | - 或者

數字(例如:-1234) - 十進位制數 :)

一些命令(例如變換)需要 24.8 定點格式的數字。定點數字是十進位制數字,乘以 256。例如

1   will be 256 (1*256) in the fixed point format;
2   will be 512 (2*256) in the fixed point format;
0.5 will be 128 (0.5*256) in the fixed point format;

以 #XXXXXXXX 格式表示的數字(例如:#80EFB434)可以用作標準 HTML 顏色格式中的顏色值:#RRGGBB,其中 RR - 紅色,GG - 綠色,BB - 藍色。例如:#FF0000 - 紅色;#00FF00 - 綠色;#0000FF - 藍色。

預定義顏色:ORANGE、BLACK、WHITE、RED、GREEN、BLUE、YELLOW。

使用者定義命令

[編輯 | 編輯原始碼]

您可以定義自己的命令(子程式)。讓我們看一個例子

//here our main program starts
print("Hello world!",0,0)
myfunc1 //here we execute our own command, which is defined at the end of our main program
stop //stop main program
myfunc:
  //here is the body of our command (named "myfunc1")
ret //Return from subprogram. Don't forget this word!

因此使用者定義的命令看起來像這樣:COMMAND_NAME: BODY OF YOUR COMMAND (SOME PIECE OF PROGRAM) ret。

您也可以動態建立命令

//Create user defined command:
user_command = { print("hello1") print("hello2") }
//And run it:
user_command
//user_command - it's address of created subprogram.

"goto" 命令

[編輯 | 編輯原始碼]

您可以從程式的某一部分跳轉到另一部分。以下是一個例子

marker1:
  blah blah
  goto marker1 #here you go to the marker1, that was declared above.

Example2

my_cool_marker:
  dot(1,1,#FF0000)
  go my_cool_marker

"while" 命令

[編輯 | 編輯原始碼]

"while" 命令用於條件迴圈:while( condition ) { actions }。例如

a = 0
while( a < 8 )
{ 
  print( "$a", a * 8, 0, WHITE ) 
  a + 1
} //Show "a" variable eight times

命令具有以下語法:COMMAND_NAME (PARAMETER1, PARAMETER2,...) 例如,讓我們執行 "dot" 命令:dot(1,1,#FF0000) 如果沒有引數,則您必須只寫命令名稱。例如:frame。一些命令可以返回值。例如:x = get_dot( 10, 10 )

華夏公益教科書