Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Game Development with Godot & GDScript Module 3

Arrays, dictionaries and packed data interview questions

Interview questions on arrays, dictionaries and packed data: warm-ups, then what each harder question tests and how a good answer starts.

9 questions: 3 warm-ups and 6 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    What is the difference between duplicate() and duplicate(true) on a GDScript array?

    Answered in the lesson Arrays and typed arrays

  2. Fresher

    How do you read a value from a GDScript dictionary when the key might be missing?

    Answered in the lesson Dictionaries and typed dictionaries

  3. Fresher to mid

    Why would you use a PackedVector2Array instead of an Array of Vector2 values?

    Answered in the lesson Packed arrays and building strings fast

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    A dungeon generator makes nine rooms with rooms.resize(9) and rooms.fill([]), then adds two bats to room 4. In the game every room holds both bats, and removing a bat from one room removes it from all of them. Explain what happened, fix the generator, and say how a test would catch it.

    What it tests
    Knowing that fill() stores one shared array in every slot, that arrays are passed by reference, and writing a test that changes one slot and checks the others.
    First step
    Print is_same(rooms[0], rooms[4]). It prints true: fill([]) evaluated [] once and put that one array in all nine slots, so appending to room 4 appended to the list every room points at.
    Follow-ups

    From the lesson Arrays and typed arrays

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Fresher to mid

    An inventory screen sorts items by rarity with sort_custom(). Its unit test with 8 items passes on every run, yet players with bags of 30 items say that items of equal rarity jump around whenever they pick something up. Explain why the test misses it, fix the sort, and improve the test.

    What it tests
    Knowing that Godot's sort is not stable, that arrays of up to 16 items hide it, and writing a comparison and a test that pin one order.
    First step
    Sort 30 items whose equal-rarity items start in a known order and check whether they keep it. On Godot 4.7.2 ties kept their order up to 16 items and moved from 17 on, so an 8-item test cannot see the problem.
    Follow-ups

    From the lesson Arrays and typed arrays

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Fresher to mid

    A settings menu starts with var settings = defaults and loads the save with settings.merge(saved, true). After a player sets the volume to 35, Reset to defaults (settings = defaults.duplicate()) keeps 35 instead of the default 80. Explain the bug, fix it, and say how you would stop it coming back.

    What it tests
    Seeing that = shares a dictionary, that merge() changes the dictionary it is called on, and protecting defaults with merged(), deep copies or a const.
    First step
    Print is_same(settings, defaults) right after loading. It prints true: settings is only a second name for defaults, so merge(saved, true) wrote the player's 35 into the defaults themselves, and every later copy of defaults carries it.
    Follow-ups

    From the lesson Dictionaries and typed dictionaries

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Fresher to mid

    A game counts kills in a dictionary keyed by enemy id, an int, saves it with JSON.stringify() and loads it back with JSON.parse_string(). After loading, kills.get(enemy_id, 0) returns 0 for every enemy, though the file holds the counts. What do you check, and how do you fix the loader?

    What it tests
    Knowing that a lookup matches the key's type as well as its value, that JSON keys are strings and its numbers come back as floats, and converting keys once while loading.
    First step
    Print the loaded dictionary and the type of one key. On Godot 4.7.2 the counts {3: 5, 7: 1} came back as { "3": 5.0, "7": 1.0 }: String keys and float values, so the int key 3 finds nothing.
    Follow-ups

    From the lesson Dictionaries and typed dictionaries

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Fresher to mid

    A drawing tool lets players sketch a path. Every mouse-motion event runs line.points.append(event.position) on a Line2D, and no point ever appears; nothing prints an error. Explain why, fix it, and say what the fix should look like for sketches of 10,000 points.

    What it tests
    Knowing that a built-in packed property returns a copy, that the change must be assigned back, and avoiding a full copy of a long path on every event.
    First step
    Print line.points.size() before and after one append. It does not change: reading line.points returned a copy, the append changed that copy, and nothing assigned it back to the Line2D.
    Follow-ups

    From the lesson Packed arrays and building strings fast

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Mid to senior

    A combat log screen takes over a second to open after a long fight of 20,000 lines; it builds its text with log += line every time it opens. A short test fight opens instantly. How do you confirm the cause, and what do you change?

    What it tests
    Measuring before changing, knowing that += on a String copies the whole text, and replacing it with a PackedStringArray and join(), or keeping the lines ready during the fight.
    First step
    Time the build alone with Time.get_ticks_usec() at 5,000, 10,000 and 20,000 lines. If twice the lines cost about four times as long, the cost is the copying of +=, which grows with the square of the lines.
    Follow-ups

    From the lesson Packed arrays and building strings fast

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Game Development with Godot & GDScript interview questions · The Game Development with Godot & GDScript track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.