mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
313 lines
15 KiB
Plaintext
313 lines
15 KiB
Plaintext
# SOME DESCRIPTIVE TITLE.
|
|
# Copyright (C) 2014-2019, Juan Linietsky, Ariel Manzur and the Godot community (CC-BY 3.0)
|
|
# This file is distributed under the same license as the Godot Engine package.
|
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
#
|
|
#, fuzzy
|
|
msgid ""
|
|
msgstr ""
|
|
"Project-Id-Version: Godot Engine latest\n"
|
|
"Report-Msgid-Bugs-To: \n"
|
|
"POT-Creation-Date: 2019-01-09 10:56+0100\n"
|
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
"MIME-Version: 1.0\n"
|
|
"Content-Type: text/plain; charset=UTF-8\n"
|
|
"Content-Transfer-Encoding: 8bit\n"
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:4
|
|
msgid "GDScript: An introduction to dynamic languages"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:7
|
|
msgid "About"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:9
|
|
msgid "This tutorial aims to be a quick reference for how to use GDScript more efficiently. It focuses on common cases specific to the language, but also covers a lot of information on dynamically typed languages."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:13
|
|
msgid "It's meant to be especially useful for programmers with little or no previous experience with dynamically typed languages."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:17
|
|
msgid "Dynamic nature"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:20
|
|
msgid "Pros & cons of dynamic typing"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:22
|
|
msgid "GDScript is a Dynamically Typed language. As such, its main advantages are that:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:25
|
|
msgid "The language is simple and easy to learn."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:26
|
|
msgid "Most code can be written and changed quickly and without hassle."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:27
|
|
msgid "Less code written means less errors & mistakes to fix."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:28
|
|
msgid "Easier to read the code (less clutter)."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:29
|
|
msgid "No compilation is required to test."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:30
|
|
msgid "Runtime is tiny."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:31
|
|
msgid "Duck-typing and polymorphism by nature."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:33
|
|
msgid "While the main disadvantages are:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:35
|
|
msgid "Less performance than statically typed languages."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:36
|
|
msgid "More difficult to refactor (symbols can't be traced)"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:37
|
|
msgid "Some errors that would typically be detected at compile time in statically typed languages only appear while running the code (because expression parsing is more strict)."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:40
|
|
msgid "Less flexibility for code-completion (some variable types are only known at run-time)."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:43
|
|
msgid "This, translated to reality, means that Godot+GDScript are a combination designed to create games quickly and efficiently. For games that are very computationally intensive and can't benefit from the engine built-in tools (such as the Vector types, Physics Engine, Math library, etc), the possibility of using C++ is present too. This allows you to still create most of the game in GDScript and add small bits of C++ in the areas that need a performance boost."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:52
|
|
msgid "Variables & assignment"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:54
|
|
msgid "All variables in a dynamically typed language are \"variant\"-like. This means that their type is not fixed, and is only modified through assignment. Example:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:58
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:80
|
|
msgid "Static:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:66
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:94
|
|
msgid "Dynamic:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:75
|
|
msgid "As function arguments:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:77
|
|
msgid "Functions are of dynamic nature too, which means they can be called with different arguments, for example:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:107
|
|
msgid "Pointers & referencing:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:109
|
|
msgid "In static languages, such as C or C++ (and to some extent Java and C#), there is a distinction between a variable and a pointer/reference to a variable. The latter allows the object to be modified by other functions by passing a reference to the original one."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:114
|
|
msgid "In C# or Java, everything not a built-in type (int, float, sometimes String) is always a pointer or a reference. References are also garbage-collected automatically, which means they are erased when no longer used. Dynamically typed languages tend to use this memory model, too. Some Examples:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:120
|
|
msgid "C++:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:136
|
|
msgid "Java:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:154
|
|
msgid "GDScript:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:166
|
|
msgid "In GDScript, only base types (int, float, string and the vector types) are passed by value to functions (value is copied). Everything else (instances, arrays, dictionaries, etc) is passed as reference. Classes that inherit :ref:`class_Reference` (the default if nothing is specified) will be freed when not used, but manual memory management is allowed too if inheriting manually from :ref:`class_Object`."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:174
|
|
msgid "Arrays"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:176
|
|
msgid "Arrays in dynamically typed languages can contain many different mixed datatypes inside and are always dynamic (can be resized at any time). Compare for example arrays in statically typed languages:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:203
|
|
msgid "And in GDScript:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:212
|
|
msgid "In dynamically typed languages, arrays can also double as other datatypes, such as lists:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:222
|
|
msgid "Or unordered sets:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:231
|
|
msgid "Dictionaries"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:233
|
|
msgid "Dictionaries are a powerful tool in dynamically typed languages. Most programmers that come from statically typed languages (such as C++ or C#) ignore their existence and make their life unnecessarily more difficult. This datatype is generally not present in such languages (or only in limited form)."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:239
|
|
msgid "Dictionaries can map any value to any other value with complete disregard for the datatype used as either key or value. Contrary to popular belief, they are efficient because they can be implemented with hash tables. They are, in fact, so efficient that some languages will go as far as implementing arrays as dictionaries."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:245
|
|
msgid "Example of Dictionary:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:252
|
|
msgid "Dictionaries are also dynamic, keys can be added or removed at any point at little cost:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:261
|
|
msgid "In most cases, two-dimensional arrays can often be implemented more easily with dictionaries. Here's a simple battleship game example:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:294
|
|
msgid "Dictionaries can also be used as data markup or quick structures. While GDScript's dictionaries resemble python dictionaries, it also supports Lua style syntax and indexing, which makes it useful for writing initial states and quick structs:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:318
|
|
msgid "For & while"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:320
|
|
msgid "Iterating in some statically typed languages can be quite complex:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:341
|
|
msgid "This is usually greatly simplified in dynamically typed languages:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:348
|
|
msgid "Container datatypes (arrays and dictionaries) are iterable. Dictionaries allow iterating the keys:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:356
|
|
msgid "Iterating with indices is also possible:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:363
|
|
msgid "The range() function can take 3 arguments:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:371
|
|
msgid "Some statically typed programming language examples:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:381
|
|
msgid "Translate to:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:394
|
|
msgid "And backwards looping is done through a negative counter:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:400
|
|
msgid "Becomes:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:408
|
|
msgid "While"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:410
|
|
msgid "while() loops are the same everywhere:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:421
|
|
msgid "Custom iterators"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:422
|
|
msgid "You can create custom iterators in case the default ones don't quite meet your needs by overriding the Variant class's ``_iter_init``, ``_iter_next``, and ``_iter_get`` functions in your script. An example implementation of a forward iterator follows:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:454
|
|
msgid "And it can be used like any other iterator:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:462
|
|
msgid "Make sure to reset the state of the iterator in ``_iter_init``, otherwise nested for-loops that use custom iterators will not work as expected."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:466
|
|
msgid "Duck typing"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:468
|
|
msgid "One of the most difficult concepts to grasp when moving from a statically typed language to a dynamic one is duck typing. Duck typing makes overall code design much simpler and straightforward to write, but it's not obvious how it works."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:473
|
|
msgid "As an example, imagine a situation where a big rock is falling down a tunnel, smashing everything on its way. The code for the rock, in a statically typed language would be something like:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:484
|
|
msgid "This way, everything that can be smashed by a rock would have to inherit Smashable. If a character, enemy, piece of furniture, small rock were all smashable, they would need to inherit from the class Smashable, possibly requiring multiple inheritance. If multiple inheritance was undesired, then they would have to inherit a common class like Entity. Yet, it would not be very elegant to add a virtual method ``smash()`` to Entity only if a few of them can be smashed."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:492
|
|
msgid "With dynamically typed languages, this is not a problem. Duck typing makes sure you only have to define a ``smash()`` function where required and that's it. No need to consider inheritance, base classes, etc."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:501
|
|
msgid "And that's it. If the object that hit the big rock has a smash() method, it will be called. No need for inheritance or polymorphism. Dynamically typed languages only care about the instance having the desired method or member, not what it inherits or the class type. The definition of Duck Typing should make this clearer:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:507
|
|
msgid "*\"When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck\"*"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:510
|
|
msgid "In this case, it translates to:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:512
|
|
msgid "*\"If the object can be smashed, don't care what it is, just smash it.\"*"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:514
|
|
msgid "Yes, we should call it Hulk typing instead."
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:516
|
|
msgid "It's possible that the object being hit doesn't have a smash() function. Some dynamically typed languages simply ignore a method call when it doesn't exist (like Objective C), but GDScript is stricter, so checking if the function exists is desirable:"
|
|
msgstr ""
|
|
|
|
#: ../../docs/getting_started/scripting/gdscript/gdscript_advanced.rst:527
|
|
msgid "Then, simply define that method and anything the rock touches can be smashed."
|
|
msgstr ""
|
|
|