ユーザ用ツール

サイト用ツール

wiki:defold:tips:008

差分

この文書の現在のバージョンと選択したバージョンの差分を表示します。

この比較画面にリンクする

次のリビジョン
前のリビジョン
wiki:defold:tips:008 [2016/04/24 13:40]
step 作成
wiki:defold:tips:008 [2016/04/30 14:01] (現在)
step
ライン 3: ライン 3:
 Defoldでロジックを書くときはLuaを使います。 Defoldでロジックを書くときはLuaを使います。
  
 +  * 拡張子は**script**
   * Luaの構文について詳しくは、リファレンス[[http://​milkpot.sakura.ne.jp/​lua/​lua51_manual_ja.html|Lua 5.1 リファレンスマニュアル]] を参照すると良いです。   * Luaの構文について詳しくは、リファレンス[[http://​milkpot.sakura.ne.jp/​lua/​lua51_manual_ja.html|Lua 5.1 リファレンスマニュアル]] を参照すると良いです。
  
-===== Syntax ===== 
  
-近日記述予定+===== 構文 ===== 
 +<sxh c++; title:​コメント>​ 
 +-- 1行コメント 
 + 
 +--[[ 
 + 
 + 複数行コメント 
 + 
 +--]] 
 +</​sxh>​ 
 + 
 +<sxh c++; title:​変数宣言>​ 
 +a = 10 
 +b = 20; c = 30 
 +foo, bar = 40, 50 
 +</​sxh>​ 
 + 
 +===== 型について ===== 
 +==== nil ==== 
 +<sxh c++; title:>​ 
 +-- 宣言しなければインスタンスが存在しないためnilになります。 
 +print(my_var) 
 + 
 +if my_var then 
 +    print("​my_var is not nil nor false!"​) 
 +end 
 +if not my_var then 
 +    print("​my_var is either nil or false!"​) 
 +end 
 +</​sxh>​ 
 +この場合if not my_var then が出力されま。 
 + 
 +==== boolean ==== 
 +<sxh c++; title:>​ 
 +flag = true 
 +if flag then 
 +    print("​flag is true"​) 
 +else 
 +    print("​flag is false"​) 
 +end 
 +</​sxh>​ 
 +この場合flag is true が出力されます。 
 + 
 +==== 数値 ==== 
 +<sxh c++; title:>​ 
 +print(10) --> prints '​10'​ 
 +print(10.0) --> '​10'​ 
 +print(10.000000000001) --> '​10.000000000001'​ 
 + 
 +a = 5 -- integer 
 +b = 7/3 -- float 
 +print(a - b) --> '​2.6666666666667'​ 
 +</​sxh>​ 
 + 
 +==== 文字列 ==== 
 +<sxh c++; title:​エスケープシーケンス>​ 
 +\a -- ベル文字(アラート) 
 + 
 +\b -- 1文字分戻る 
 + 
 +\f -- ページ送り(クリア) 
 + 
 +\n -- 改行、復帰 
 + 
 +\r -- 同じ行の先頭に戻る 
 + 
 +\t -- 水平タブ 
 + 
 +\v -- 垂直タブ 
 + 
 +\\ -- \を表示 
 + 
 +\" -- ダブルクォーテーション("​)を表示 
 + 
 +\' -- シングルクォーテーション('​)を表示 
 + 
 +\[ -- left square bracket 
 + 
 +\] -- right square bracket 
 + 
 +\ddd -- character denoted by its numeric value where ddd is a sequence of up to three decimal digits 
 +</​sxh>​ 
 + 
 +<sxh c++; title:​使用例>​ 
 +my_string = "​hello"​ 
 +another_string = '​world'​ 
 +print(my_string .. another_string) --> "​helloworld"​ 
 + 
 +print("​10.2"​ + 1) --> 11.2 
 +print(my_string + 1) -- error, can't convert "​hello"​ 
 +print(my_string .. 1) --> "​hello1"​ 
 + 
 +print("​one\nstring"​) --> one 
 +                     ​-->​ string 
 + 
 +print("​\097bc"​) --> "​abc"​ 
 + 
 +multi_line_string = [[ 
 +Here is a chunk of text that runs over several lines. This is all 
 +put into the string and is sometimes very handy. 
 +]] 
 +</​sxh>​ 
 + 
 +==== 関数 ==== 
 +<sxh c++; title:>​ 
 +-- MyPlusという名の関数で、 a + b の結果を返す 
 +MyPlus = function(a, b) 
 +    return a + b 
 +end 
 + 
 +-- MyPlusという名の関数で、 a * b の結果を返す 
 +function MyMultiple(a,​ b) 
 +    return a * b 
 +end 
 + 
 +-- 関数を引数に渡すことができる 
 +function operate(func,​ a, b) 
 +    return func(a, b) 
 +end 
 +-- 使用例 
 +print(operate(MyPlus,​ 4, 5)) --> 9 
 + 
 + 
 +-- Create an adder function and return it 
 +function create_adder(n) 
 +    return function(a) 
 +        return a + n 
 +    end 
 +end 
 + 
 +adder = create_adder(2) -- n に2が入った状態で初期化。 
 +print(adder(3)) --> 2+3 = 5 
 +print(adder(10)) --> 2+10 = 12 
 +</​sxh>​ 
 + 
Permalink wiki/defold/tips/008.1461505211.txt.gz · 最終更新: 2016/04/24 13:40 by step

oeffentlich