これに対する答えは恥ずかしいほど簡単だと思いますが、それでもわかりません (これらの言語をまったく知らないという事実が当てはまる可能性があります)。私が必要としているのは、次のように機能するスクリプトです。
- まず、!random のようなコマンドと 1 から 100 の範囲の数字 (数字は成功確率を % で表す) を入力します [このように: !random 78]
- 次に、与えられた確率に基づいて、成功したか失敗したかを選択します [たとえば、!random 78 の場合、結果が「成功」になる確率は 78% です]。
- 次に、結果が何であるか(「成功」または「失敗」)がチャネルに公開メッセージを表示します。
オンライン テキスト RPG セッション用にこれが必要です。また、私の下手な英語で申し訳ありません。
コードがどのように見えるか:
__module_name__ = "HexChat Randomiser"
__module_version__ = "0.1"
__module_description__ = "A randomiser for HexChat."
import random
import xchat
def callback(word, world_eol, userdata):
number = word[1]
if random_chance(number):
print ("Success")
else:
print ("Failure")
def random_chance(percent_chance):
return random.randrange(1, 101) > (100 - percent_chance)
xchat.hook_command("random", callback, help="/random <number>")
エラー:
Traceback (most recent call last):
File "<string>", line 10, in callback
File "<string>", line 17, in random_chance
TypeError: unsupported operand type(s) for -: 'int' and 'str'