瀏覽代碼

Step-by-step scripting: Reorder functions

Max Hilbrunner 7 年之前
父節點
當前提交
a7e0c78b40
共有 1 個文件被更改,包括 8 次插入8 次删除
  1. 8 8
      getting_started/step_by_step/scripting.rst

+ 8 - 8
getting_started/step_by_step/scripting.rst

@@ -284,12 +284,12 @@ The final script should look like this:
 
     extends Panel
 
-    func _on_button_pressed():
-        get_node("Label").text = "HELLO!"
-
     func _ready():
         get_node("Button").connect("pressed", self, "_on_button_pressed")
 
+    func _on_button_pressed():
+        get_node("Label").text = "HELLO!"
+
  .. code-tab:: csharp
 
     using Godot;
@@ -298,15 +298,15 @@ The final script should look like this:
     // this is case sensitive!
     public class sayhello : Panel
     {
-        public void _OnButtonPressed()
+        public override void _Ready()
         {
-            var label = (Label)GetNode("Label");
-            label.Text = "HELLO!";
+            GetNode("Button").Connect("pressed", this, nameof(_OnButtonPressed));
         }
 
-        public override void _Ready()
+        public void _OnButtonPressed()
         {
-            GetNode("Button").Connect("pressed", this, nameof(_OnButtonPressed));
+            var label = (Label)GetNode("Label");
+            label.Text = "HELLO!";
         }
     }