Blame
|
1 | <!-- Generated from applied-computing-au vic/unit3-4/sat/C06-2026/C06-Reference-Godot by port-reference-godot-to-wiki.py — do not hand-edit; re-run the port. --> |
||||||
|
2 | # Data Types — GDScript |
||||||
| 3 | ||||||||
| 4 | ||||||||
| 5 | **Skill codes on this page** |
|||||||
| 6 | ||||||||
| 7 | | Code | Level | Skill | |
|||||||
| 8 | |---|---|---| |
|||||||
| 9 | | C613 | 1–2 | text data | |
|||||||
| 10 | | C614 | 1–2 | numeric data | |
|||||||
| 11 | | C615 | 1–2 | Boolean data | |
|||||||
| 12 | | C629 | 3–4 | outlines, in the internal documentation, why the selected data types were used | |
|||||||
| 13 | ||||||||
| 14 | **Definition.** A *data type* classifies a variable: what data it can contain and how that data can be manipulated. |
|||||||
| 15 | ||||||||
| 16 | At level 1–2 the skill is **identifying** the three data families in your own code. Using them with *stated* types is C628/C634 — see [Local and Global Variables](/sd/C06/Local%20and%20Global%20Variables). |
|||||||
| 17 | ||||||||
| 18 | **Earns the tick:** one labelled line per family — text, numeric, Boolean — in code that runs. |
|||||||
| 19 | ||||||||
| 20 | ## C613 — Text data |
|||||||
| 21 | ||||||||
| 22 | **Definitions.** *Character:* a single meaningful unit — a letter, digit, punctuation mark, symbol or space. *String:* a sequence of characters. |
|||||||
| 23 | ||||||||
| 24 | ### Character |
|||||||
| 25 | ||||||||
| 26 | GDScript has no separate character type — use a one-character String: |
|||||||
| 27 | ||||||||
| 28 | ```gdscript |
|||||||
| 29 | var chr_var: String = "A" # C613 — text: character |
|||||||
| 30 | ``` |
|||||||
| 31 | ||||||||
| 32 | ### String |
|||||||
| 33 | ||||||||
| 34 | ```gdscript |
|||||||
| 35 | var str_var: String = "Hello!" # C613 — text: string |
|||||||
| 36 | ``` |
|||||||
| 37 | ||||||||
| 38 | ## C614 — Numeric data |
|||||||
| 39 | ||||||||
| 40 | **Definitions.** *Integer:* whole positive and negative numbers. *Floating point:* computer representation of real numbers, with decimal places. *Numeric:* both families together. |
|||||||
| 41 | ||||||||
| 42 | ### Integer |
|||||||
| 43 | ||||||||
| 44 | ```gdscript |
|||||||
| 45 | var int_var: int = 42 # C614 — numeric: integer |
|||||||
| 46 | ``` |
|||||||
| 47 | ||||||||
| 48 | ### Floating point |
|||||||
| 49 | ||||||||
| 50 | ```gdscript |
|||||||
| 51 | var float_var: float = 3.14 # C614 — numeric: floating point |
|||||||
| 52 | ``` |
|||||||
| 53 | ||||||||
| 54 | ## C615 — Boolean data |
|||||||
| 55 | ||||||||
| 56 | **Definition.** A data type with one of two possible values, usually referred to as False and True. |
|||||||
| 57 | ||||||||
| 58 | ```gdscript |
|||||||
| 59 | var bool_var: bool = true # C615 — Boolean |
|||||||
| 60 | ``` |
|||||||
| 61 | ||||||||
| 62 | ## Spot them in a studied project |
|||||||
| 63 | ||||||||
| 64 | ```gdscript |
|||||||
| 65 | # tile-matching-game — card.gd / game.gd |
|||||||
| 66 | var pair_id := "" # C613 — text: a String, inferred from "" |
|||||||
| 67 | var score := 0 # C614 — numeric: an int |
|||||||
| 68 | @export var flip_back_delay := 1.2 # C614 — numeric: a float |
|||||||
| 69 | var is_face_up := false # C615 — Boolean |
|||||||
| 70 | ``` |
|||||||
| 71 | ||||||||
| 72 | These use `:=` inference — fine, as long as your comment names the type (see the warning in [Local and Global Variables](/sd/C06/Local%20and%20Global%20Variables)). |
|||||||
| 73 | ||||||||
| 74 | ## Date/time |
|||||||
| 75 | ||||||||
| 76 | No skill code of its own — it counts toward the level 9–10 *range* (C657). |
|||||||
| 77 | ||||||||
| 78 | ```gdscript |
|||||||
| 79 | var dt_var = Time.get_datetime_dict_from_system() # counts toward C657 — range of types |
|||||||
| 80 | ``` |
|||||||
| 81 | ||||||||
| 82 | That call returns a Dictionary of year, month, day, hour and so on — which is also a **record**; see [Data Structures](/sd/C06/Data%20Structures). |
|||||||
| 83 | ||||||||
| 84 | ## C629 — Why these data types |
|||||||
| 85 | ||||||||
| 86 | Level 3–4 asks you to **outline** the reason in internal documentation — a phrase is enough: |
|||||||
| 87 | ||||||||
| 88 | ```gdscript |
|||||||
| 89 | var balance: float = 20.00 # C629 — float: money needs decimal places |
|||||||
| 90 | var card_id: String = "" # C629 — String: digits never used in a calculation |
|||||||
| 91 | ``` |
|||||||
| 92 | ||||||||
| 93 | The reasons come from how each type behaves — the input/storage/output view is in [Data Type Characteristics](/sd/C06/Data%20Type%20Characteristics). |
|||||||
| 94 | ||||||||
| 95 | **Also name it when you do it:** *casting* — converting a value from one type to another — is everyday Godot: `int($ZoneInput.text)`, `str(fares[0])`. |
|||||||
| 96 | ||||||||
| 97 | ## Check Your Understanding |
|||||||
| 98 | ||||||||
| 99 | 1. Name the three level 1–2 data families and their codes. |
|||||||
| 100 | ||||||||
| 101 | >| ### Answer |
|||||||
| 102 | >| Text C613, numeric C614, Boolean C615. |
|||||||
| 103 | ||||||||
| 104 | 2. Why does `var trips = 0` earn nothing for data types? |
|||||||
| 105 | ||||||||
| 106 | >| ### Answer |
|||||||
| 107 | >| No type is stated or named in a comment — there is nothing for the marker to assess. |
|||||||
| 108 | ||||||||
| 109 | 3. What is casting? Give one Godot example. |
|||||||
| 110 | ||||||||
| 111 | >| ### Answer |
|||||||
| 112 | >| Converting a value between types — e.g. `int($ZoneInput.text)` turns the typed text into a number. |
|||||||
