Improve the preload and load descriptions

(cherry picked from commit 13298ed873)
This commit is contained in:
Tomasz Chabora 2020-06-28 20:51:46 +02:00 committed by Rémi Verschelde
parent cb9bc18102
commit 5b7eb3fd3f
1 changed files with 8 additions and 8 deletions

View File

@ -628,11 +628,11 @@
<argument index="0" name="path" type="String"> <argument index="0" name="path" type="String">
</argument> </argument>
<description> <description>
Loads a resource from the filesystem located at [code]path[/code]. Loads a resource from the filesystem located at [code]path[/code]. The resource is loaded on the method call (unless it's referenced already elsewhere, e.g. in another script or in the scene), which might cause slight delay, especially when loading scenes. To avoid unnecessary delays when loading something multiple times, either store the resource in a variable or use [method preload].
[b]Note:[/b] Resource paths can be obtained by right-clicking on a resource in the FileSystem dock and choosing [b]Copy Path[/b]. [b]Note:[/b] Resource paths can be obtained by right-clicking on a resource in the FileSystem dock and choosing "Copy Path" or by dragging the file from the FileSystem dock into the script.
[codeblock] [codeblock]
# Load a scene called main located in the root of the project directory. # Load a scene called main located in the root of the project directory and cache it in a variable.
var main = load("res://main.tscn") var main = load("res://main.tscn") # main will contain a PackedScene resource.
[/codeblock] [/codeblock]
[b]Important:[/b] The path must be absolute, a local path will just return [code]null[/code]. [b]Important:[/b] The path must be absolute, a local path will just return [code]null[/code].
</description> </description>
@ -806,11 +806,11 @@
<argument index="0" name="path" type="String"> <argument index="0" name="path" type="String">
</argument> </argument>
<description> <description>
Returns a resource from the filesystem that is loaded during script parsing. Returns a [Resource] from the filesystem located at [code]path[/code]. The resource is loaded during script parsing, i.e. is loaded with the script and [method preload] effectively acts as a reference to that resource. Note that the method requires a constant path. If you want to load a resource from a dynamic/variable path, use [method load].
[b]Note:[/b] Resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path". [b]Note:[/b] Resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path" or by dragging the file from the FileSystem dock into the script.
[codeblock] [codeblock]
# Load a scene called main located in the root of the project directory. # Instance a scene.
var main = preload("res://main.tscn") var diamond = preload("res://diamond.tscn").instance()
[/codeblock] [/codeblock]
</description> </description>
</method> </method>