问题描述
我想在MMO或MOBA游戏中创建一个“快捷键”,通过按键来激活技能。
我找到了一个gdscript教程,但它使用点击而不是按键。我尝试更改代码以检查何时用housing = fetch_california_housing()
X_train_full,X_test,y_train_full,y_test = train_test_split(housing.data,housing.target,random_state=42)
X_train,X_valid,y_train,y_valid = train_test_split(X_train_full,random_state=42)
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_valid = scaler.transform(X_valid)
X_test = scaler.transform(X_test)
input_A = keras.layers.Input(shape=[5],name="wide_input")
input_B = keras.layers.Input(shape=[6],name="deep_input")
hidden1 = keras.layers.Dense(30,activation="relu")(input_B)
hidden2 = keras.layers.Dense(30,activation="relu")(hidden1)
concat = keras.layers.concatenate([input_A,hidden2])
output = keras.layers.Dense(1,name="output")(concat)
model = keras.models.Model(inputs=[input_A,input_B],outputs=[output])
model.compile(loss='mse',optimizer=keras.optimizers.SGD(lr=1e-3))
X_train_A,X_train_B = X_train[:,:5],X_train[:,2:]
X_valid_A,X_valid_B = X_valid[:,X_valid[:,2:]
X_test_A,X_test_B = X_test[:,X_test[:,2:]
X_new_A,X_new_B = X_test_A[:3],X_test_B[:3]
history = model.fit((X_train_A,X_train_B),epochs=20,validation_data=((X_valid_A,X_valid_B),y_valid))
mse_test = model.evaluate((X_test_A,X_test_B),y_test)
y_pred = model.predict((X_new_A,X_new_B))
按下“ K”,但这没用。
这是错误:
if Input.is_key_pressed(KEY_K):
以下是该教程的链接:https://kidscancode.org/godot_recipes/ui/cooldown_button/
这是原始代码:
E 0:00:40.192 emit_signal: Error calling method from signal 'pressed': 'TextureButton(AbilityButton.gd)::_on_key_pressed':
Method expected 1 arguments,but called with 0..<C++ Source> core/object.cpp:1228 @ emit_signal()
这是我的代码:
extends TextureButton
onready var time_label = $Counter/Value
export var cooldown = 1.0
func _ready():
print_tree_pretty()
time_label.hide()
$Sweep.value = 0
$Sweep.texture_progress = texture_normal
$Timer.wait_time = cooldown
set_process(false)
func _process(delta):
time_label.text = "%3.1f" % $Timer.time_left
$Sweep.value = int(($Timer.time_left / cooldown) * 100)
func _on_Timer_timeout():
print("ability ready")
$Sweep.value = 0
disabled = false
time_label.hide()
set_process(false)
func _on_AbilityButton_pressed():
disabled = true
set_process(true)
$Timer.start()
time_label.show()
func _on_key_pressed():
pass
解决方法
错误消息说明了一切:Method expected 1 arguments,but called with 0
。
这意味着绑定到信号的方法是用一个参数定义的,但是信号发送0个参数并且引擎会大喊。
您可以在BaseButton
文档中检查信号发送的自变量(0)。
尝试删除event
:
func _on_key_pressed(event):
→
func _on_key_pressed():
祝你好运!