Browse Source

Added guide to edit variables (#3049)

* Added guide to edit variables

* Style updated

removed static typing
added line between function
added space after #

* Apply suggestions from code review

Co-authored-by: Max Hilbrunner <[email protected]>
AntonWetzel 5 years ago
parent
commit
a364907465
1 changed files with 24 additions and 0 deletions
  1. 24 0
      tutorials/misc/running_code_in_the_editor.rst

+ 24 - 0
tutorials/misc/running_code_in_the_editor.rst

@@ -98,6 +98,30 @@ Now let's choose which code runs when. Modify your ``_process()`` function to lo
 
 Save the script. Now the object will spin clockwise in the editor, but if you run the game, it will spin counter-clockwise.
 
+Editing variables
+-----------------
+Add and export a variable speed to the script. The function set_speed after "setget" is executed with your input to change the variable.
+Modify  ``_process()`` to include the rotation speed.
+
+.. tabs::
+ .. code-tab:: gdscript GDScript
+
+    tool
+    extends Sprite
+
+
+    export var speed = 1 setget set_speed
+
+
+    # Update speed and reset the rotation.
+    func set_speed(new_speed):
+    	speed = new_speed
+    	rotation_degrees = 0
+
+
+    func _process(delta):
+    	rotation_degrees += 180 * delta * speed
+
 .. note:: Code from other nodes doesn't run in the editor. Your access to other nodes is limited. You can access the tree and nodes, and their default properties, but you can't access user variables. If you want to do so, other nodes have to run in the editor too. AutoLoad nodes cannot be accessed in the editor at all.
 
 Instancing scenes