Warcraft3のMOD総合案内
- Jass Script/ライブラリ集/Handles の編集
[
ファイルを添付する
] [
このページの名前を変更する
] [
このページを編集する
]
サイトメニュー
ページ一覧
最近の更新ページ
使い方
トップへ戻る
Jass講座
[[トップ>FrontPage]] > [[MAP作成]] > [[Jass Script]] > [[ライブラリ集>Jass Script/ライブラリ集]] > Handles &br; *ライブラリ [#n3d778dd] //hashtableはgamecacheと同じような働きを持ちますが、値の参照にStringではなくintegerを用いることで処理がより安全で軽量になります。 //hashtableの定義 globals hashtable HashT = InitHashtable() endglobals //ライブラリ library Handles //GetHandleIdは以前のH2Iと同じ働きを持ちます。 //StringHashはS2Iと同じですが、これはあらゆる文字列が扱えます。 // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けて、Integerを保存 function SetHandleInteger takes handle whichhandle, string whichVariable, integer value returns nothing call SaveInteger(HashT,GetHandleId(whichhandle),StringHash(whichVariable), value) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、Integerを取得 function GetHandleInteger takes handle whichhandle, string whichVariable returns integer return LoadInteger(HashT,GetHandleId(whichhandle),StringHash(whichVariable)) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けて、Realを保存 function SetHandleReal takes handle whichhandle, string whichVariable, real value returns nothing call SaveReal(HashT, GetHandleId(whichhandle),StringHash(whichVariable),value) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、Realを取得 function GetHandleReal takes handle whichhandle, string whichVariable returns real return LoadReal(HashT, GetHandleId(whichhandle),StringHash(whichVariable)) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けて、Booleanを保存 function SetHandleBoolean takes handle whichhandle, string whichVariable, boolean value returns nothing call SaveBoolean(HashT, GetHandleId(whichhandle),StringHash(whichVariable),value) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、Booleanを取得 function GetHandleBoolean takes handle whichhandle, string whichVariable returns boolean return LoadBoolean(HashT, GetHandleId(whichhandle),StringHash(whichVariable)) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けて、文字列(string)を保存 function SetHandleString takes handle whichhandle, string whichVariable, string value returns nothing call SaveStr(HashT, GetHandleId(whichhandle),StringHash(whichVariable), value) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、文字列(string)を取得 function GetHandleString takes handle whichhandle, string whichVariable returns string return LoadStr(HashT,GetHandleId(whichhandle),StringHash(whichVariable)) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、任意の値(Agent)を保存 function SetHandleAgent takes handle whichHandle, string whichVariable, agent value returns nothing call SaveAgentHandle(HashT, GetHandleId(whichHandle),StringHash(whichVariable),value) endfunction //******************************************************* // タイマー以外のHandle型変数を取得する関数を作るときは // // 1, ここの関数を、このライブラリ内にコピペ // 2, 関数名を適当に変更(たとえば、GetHandleUnit,GetUnitHandle) // 3, 関数内のAPIを変更 (たとえば、LoadTimerHandle -> LoadUnitHandle)これは、common.jに記載されている // 4, 戻り値を変更 (たとえば、returns timer -> returns unit) // // と、するように。 // // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、timerを取得 function GetHandleTimer takes handle whichHandle, string whichVariable returns timer return LoadTimerHandle(HashT,GetHandleId(whichHandle),StringHash(whichVariable )) endfunction //******************************************************* function FlushHandle takes handle whichHandle returns nothing call FlushChildHashtable(HashT, GetHandleId(whichHandle)) endfunction endlibrary **使い方のサンプル[#kb10c662] ユニットやタイマーに、データを関連付けて使うことが多いだろう。 たとえば、ユニットであれば、ノックバックを利用する場合の移動速度などなど。あらゆる情報を関連付けられる。 また、タイマーであれば、''TimerStart'' 関数を使うときに、引数として利用できる。 -''function Test'' を実行後、10秒でユニットを殺す例 --Handlesのライブラリに追加する項目 function GetHandleUnit takes handle subject,string name returns unit return GetUnitHandle(GetHandleId(subject) , StringHash(name)) endfunction --メイン。''function test'' がまず実行される。 // TimerStart で呼ばれる関数なので、引数を設定できない。 function KillVictim takes nothing returns nothing //GetHandleUnitを使うために、CountDownTimerを取得する local timer CountDownTimer = GetExpiredTimer() //VICTIM をHashtableから取得 local unit VICTIM = GetHandleUnit(CountDownTimer, "UnitToKill") //VICTIMを殺す call KillUnit(VICTIM) //使い終わったので、CountDownTimerに関連付けられた全てのHashtableを破棄。 call FlushHandle(CountDownTimer) //使い終わったタイマーを削除。削除の前にポーズをする。 call PauseTimer(CountDownTimer) call DestroyTimer(CountDownTimer) //変数のnull化 set CountDownTimer = null set VICTIM = null endfunction function test takes unit VICTIM returns nothing //タイマーを作成 local timer CountDownTimer = CreateTimer() // CountDownTimer に、VICTIM を、"UnitToKill"というキーワードをつけて保存 call SetHandleAgent(CountDownTimer,"UnitToKill", VICTIM) //タイマーを起動 call TimerStart(CountDownTimer, 10.0, false, function KillVictim) //変数のnull化 set CountDownTimer = null endfunction **変数の保存 [#n1c8f0c8] 上の例にならって説明する。 :書式|call ''SetHandleAgent''( handle &color(blue){''AnyHandle1''}; , string &color(green){''Key''}; , handle &color(red){''AnyHandle2''}; ) &color(blue){''AnyHandle1''}; に対して、&color(green){''Key''}; というキーワードをつけて、 &color(red){''AnyHandle2''}; を保存。 保存したい値が整数の場合は ''SetHandleInteger''、実数の場合は ''SetHandleReal''、文字列の場合は ''SetHandleString''、Boolean型の場合は ''SetHandleBoolean'' を使う。それ以外のものは%%''"変数名"''の部分を保存したい変数にあわせて変える(UnitならSetHandleUnit,TimerならSetHandleTimer等)。%%ver1.24bからは、すべて''SetHandleAgent''を使う。 ''Key'' には、わかりやすいキーワードをつけるといい。たとえば call SetHandleInteger( UnitA, "GoldCost", 1200) という風に。 **変数の取得 [#m785b69d] 上の例にならって説明する。 :書式|call ''GetHandleTimer''( handle &color(blue){''AnyHandle1''}; , string &color(green){''Key''};) &color(blue){''AnyHandle1''}; に対して、&color(green){''Key''}; というキーワードで保存してある &color(red){''timer''}; を取得する。 取得したい値が整数の場合は ''GetHandleInteger''、実数の場合は ''GetHandleReal''、文字列の場合は ''GetHandleString''、Boolean型の場合は ''GetHandleBoolean'' を使う。それ以外のものはすべて ''handle型変数'' なので、 ''GetHandle〜'' が使える。 値が存在しない場合、''null''が返される。 上の例なら set i = GetHandleInteger( UnitA, "GoldCost") という風に。i の値には 1200 が代入される。 **より賢い使い方 [#m7a24be3] 構造体を使えば、より書式を簡略化できる。 構造体の正体はIntegerなので、変数をそのまま ''SetHandleInteger'' するだけで、関連項目全てを記憶できるほか、値を変更したときも ''SetHandleInteger'' をやり直す必要がない。 詳しくは、[[構造体>Jass Script/モジュール、クラス#structprofit]]のページで。
タイムスタンプを変更しない
[[トップ>FrontPage]] > [[MAP作成]] > [[Jass Script]] > [[ライブラリ集>Jass Script/ライブラリ集]] > Handles &br; *ライブラリ [#n3d778dd] //hashtableはgamecacheと同じような働きを持ちますが、値の参照にStringではなくintegerを用いることで処理がより安全で軽量になります。 //hashtableの定義 globals hashtable HashT = InitHashtable() endglobals //ライブラリ library Handles //GetHandleIdは以前のH2Iと同じ働きを持ちます。 //StringHashはS2Iと同じですが、これはあらゆる文字列が扱えます。 // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けて、Integerを保存 function SetHandleInteger takes handle whichhandle, string whichVariable, integer value returns nothing call SaveInteger(HashT,GetHandleId(whichhandle),StringHash(whichVariable), value) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、Integerを取得 function GetHandleInteger takes handle whichhandle, string whichVariable returns integer return LoadInteger(HashT,GetHandleId(whichhandle),StringHash(whichVariable)) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けて、Realを保存 function SetHandleReal takes handle whichhandle, string whichVariable, real value returns nothing call SaveReal(HashT, GetHandleId(whichhandle),StringHash(whichVariable),value) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、Realを取得 function GetHandleReal takes handle whichhandle, string whichVariable returns real return LoadReal(HashT, GetHandleId(whichhandle),StringHash(whichVariable)) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けて、Booleanを保存 function SetHandleBoolean takes handle whichhandle, string whichVariable, boolean value returns nothing call SaveBoolean(HashT, GetHandleId(whichhandle),StringHash(whichVariable),value) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、Booleanを取得 function GetHandleBoolean takes handle whichhandle, string whichVariable returns boolean return LoadBoolean(HashT, GetHandleId(whichhandle),StringHash(whichVariable)) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けて、文字列(string)を保存 function SetHandleString takes handle whichhandle, string whichVariable, string value returns nothing call SaveStr(HashT, GetHandleId(whichhandle),StringHash(whichVariable), value) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、文字列(string)を取得 function GetHandleString takes handle whichhandle, string whichVariable returns string return LoadStr(HashT,GetHandleId(whichhandle),StringHash(whichVariable)) endfunction // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、任意の値(Agent)を保存 function SetHandleAgent takes handle whichHandle, string whichVariable, agent value returns nothing call SaveAgentHandle(HashT, GetHandleId(whichHandle),StringHash(whichVariable),value) endfunction //******************************************************* // タイマー以外のHandle型変数を取得する関数を作るときは // // 1, ここの関数を、このライブラリ内にコピペ // 2, 関数名を適当に変更(たとえば、GetHandleUnit,GetUnitHandle) // 3, 関数内のAPIを変更 (たとえば、LoadTimerHandle -> LoadUnitHandle)これは、common.jに記載されている // 4, 戻り値を変更 (たとえば、returns timer -> returns unit) // // と、するように。 // // whichHandle(任意のhandle型変数) + whichVariable(任意のキーワード) に関連付けられた、timerを取得 function GetHandleTimer takes handle whichHandle, string whichVariable returns timer return LoadTimerHandle(HashT,GetHandleId(whichHandle),StringHash(whichVariable )) endfunction //******************************************************* function FlushHandle takes handle whichHandle returns nothing call FlushChildHashtable(HashT, GetHandleId(whichHandle)) endfunction endlibrary **使い方のサンプル[#kb10c662] ユニットやタイマーに、データを関連付けて使うことが多いだろう。 たとえば、ユニットであれば、ノックバックを利用する場合の移動速度などなど。あらゆる情報を関連付けられる。 また、タイマーであれば、''TimerStart'' 関数を使うときに、引数として利用できる。 -''function Test'' を実行後、10秒でユニットを殺す例 --Handlesのライブラリに追加する項目 function GetHandleUnit takes handle subject,string name returns unit return GetUnitHandle(GetHandleId(subject) , StringHash(name)) endfunction --メイン。''function test'' がまず実行される。 // TimerStart で呼ばれる関数なので、引数を設定できない。 function KillVictim takes nothing returns nothing //GetHandleUnitを使うために、CountDownTimerを取得する local timer CountDownTimer = GetExpiredTimer() //VICTIM をHashtableから取得 local unit VICTIM = GetHandleUnit(CountDownTimer, "UnitToKill") //VICTIMを殺す call KillUnit(VICTIM) //使い終わったので、CountDownTimerに関連付けられた全てのHashtableを破棄。 call FlushHandle(CountDownTimer) //使い終わったタイマーを削除。削除の前にポーズをする。 call PauseTimer(CountDownTimer) call DestroyTimer(CountDownTimer) //変数のnull化 set CountDownTimer = null set VICTIM = null endfunction function test takes unit VICTIM returns nothing //タイマーを作成 local timer CountDownTimer = CreateTimer() // CountDownTimer に、VICTIM を、"UnitToKill"というキーワードをつけて保存 call SetHandleAgent(CountDownTimer,"UnitToKill", VICTIM) //タイマーを起動 call TimerStart(CountDownTimer, 10.0, false, function KillVictim) //変数のnull化 set CountDownTimer = null endfunction **変数の保存 [#n1c8f0c8] 上の例にならって説明する。 :書式|call ''SetHandleAgent''( handle &color(blue){''AnyHandle1''}; , string &color(green){''Key''}; , handle &color(red){''AnyHandle2''}; ) &color(blue){''AnyHandle1''}; に対して、&color(green){''Key''}; というキーワードをつけて、 &color(red){''AnyHandle2''}; を保存。 保存したい値が整数の場合は ''SetHandleInteger''、実数の場合は ''SetHandleReal''、文字列の場合は ''SetHandleString''、Boolean型の場合は ''SetHandleBoolean'' を使う。それ以外のものは%%''"変数名"''の部分を保存したい変数にあわせて変える(UnitならSetHandleUnit,TimerならSetHandleTimer等)。%%ver1.24bからは、すべて''SetHandleAgent''を使う。 ''Key'' には、わかりやすいキーワードをつけるといい。たとえば call SetHandleInteger( UnitA, "GoldCost", 1200) という風に。 **変数の取得 [#m785b69d] 上の例にならって説明する。 :書式|call ''GetHandleTimer''( handle &color(blue){''AnyHandle1''}; , string &color(green){''Key''};) &color(blue){''AnyHandle1''}; に対して、&color(green){''Key''}; というキーワードで保存してある &color(red){''timer''}; を取得する。 取得したい値が整数の場合は ''GetHandleInteger''、実数の場合は ''GetHandleReal''、文字列の場合は ''GetHandleString''、Boolean型の場合は ''GetHandleBoolean'' を使う。それ以外のものはすべて ''handle型変数'' なので、 ''GetHandle〜'' が使える。 値が存在しない場合、''null''が返される。 上の例なら set i = GetHandleInteger( UnitA, "GoldCost") という風に。i の値には 1200 が代入される。 **より賢い使い方 [#m7a24be3] 構造体を使えば、より書式を簡略化できる。 構造体の正体はIntegerなので、変数をそのまま ''SetHandleInteger'' するだけで、関連項目全てを記憶できるほか、値を変更したときも ''SetHandleInteger'' をやり直す必要がない。 詳しくは、[[構造体>Jass Script/モジュール、クラス#structprofit]]のページで。
テキスト整形のルールを表示する