アクマくん 2023/10/16 01:30

ティラノ×JavaScriptメモ

ティラノで嵌ったのでメモ

tyranoscript_v521b

tyranoscript_v521f

にバージョンアップ後に、
JavaScriptが上手く動作しなくなったのを、
3か月近く経過してから気づきました。

修正前(動かないver)
with(tyrano.plugin.kag) {

document.addEventListener('keypress', keypress_ivent,);

var input = "";
var inputFlg = 0;

function keypress_ivent(e) {

 if(e.key === 'a' && input === ""){
   input = e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test1");
 } else if(e.key === 'k' && input === 'a'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test2");
 } else if(e.key === 'u' && input === 'ak'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test3");
 } else if(e.key === 'm' && input === 'aku'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test4");
 } else if(e.key === 'a' && input === 'akum'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test5");
 } else if(e.key === 'k' && input === 'akuma'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test6");
 } else if(e.key === 'u' && input === 'akumak'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test7");
 } else if(e.key === 'n' && input === 'akumaku'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test8");
   stat.f.commandFlg = 1;
 } else {
   input = "";
   console.log("miss");
 }

}
}


修正後(動いたver)
with(tyrano.plugin.kag) {
document.addEventListener('keydown', keypress_ivent);

document.addEventListener('keypress', keypress_ivent,);

var input = "";
var inputFlg = 0;

function keypress_ivent(e) {

 if(e.key === 'a' && input === ""){
   input = e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test1");
 } else if(e.key === 'k' && input === 'a'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test2");
 } else if(e.key === 'u' && input === 'ak'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test3");
 } else if(e.key === 'm' && input === 'aku'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test4");
 } else if(e.key === 'a' && input === 'akum'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test5");
 } else if(e.key === 'k' && input === 'akuma'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test6");
 } else if(e.key === 'u' && input === 'akumak'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test7");
 } else if(e.key === 'n' && input === 'akumaku'){
   input = input + e.key;
   console.log(e.key);
   stat.f.commandValue = input;
   console.log("test8");
   stat.f.commandFlg = 1;
 } else {
   input = "";
   console.log("miss");
 }

}
}



ティラノ画面で、
キーボードを打つと打ったキーに合わせて、
変数に格納して、
きてほしいキーが揃ったら、
フラグを立てるというロジックですが、

どうも、
バージョンアップ後に動作確認したところ、
キーボードを打った時に、
JavaScript上で検知しなくなりました。

2,3時間ほど試行錯誤した結果、
なぜか

document.addEventListener('keydown', keypress_ivent);

この一行を追加しただけで、動くようになりました。

いやいや、それはおかしいだろう。
と初心者でもわかるような謎の挙動ですが、
他にどうしようもなかったので、
一応これで解決と言う事で。



ただ、これをティラノ上で一度動作させると、
ゲーム起動中は動作しっぱしなので、
全然いけてません。


なので、これは後々お蔵入りのコードになるとは思いますが、
せっかく書いたので現時点では一応残しておきます。


前から思ってましたが、
ティラノでJavaScriptとかHTMLを使うのは、
なかなかハードルが高いですorz

最新の記事

月別アーカイブ

限定特典から探す

記事を検索