Strings in My Game

What Are Strings?

Strings are pieces of text stored in programming.

Strings are written inside quotation marks:

"Hello World"

Games use strings for:

  • names
  • dialogue
  • labels
  • IDs
  • messages
  • text displayed on screen

My game uses strings throughout many systems.


Why Strings Are Important

Without strings, the game could not:

  • display text
  • identify objects
  • show messages
  • label enemies or players
  • display scores and UI information

Strings help organize and communicate information in the game.


Example 1: Object IDs

My game uses strings to identify objects.

id: "EnemyElon"

Explanation

This string:

  • gives the enemy a unique name
  • helps identify the object
  • allows collision and filtering systems to work

Another example:

id: "Octopus"

This identifies the player object.


Example 2: NPC Dialogue

Strings are used for character greetings.

greeting: "Hello! I'm a wizard! ✨"

Explanation

This string stores:

  • NPC dialogue
  • text shown to the player
  • interactive game messages

Example 3: Scoreboard Text

Strings are used in the scoreboard display.

 Score: ${this.score}

Explanation

This string:

  • combines text with score values
  • displays information to the player
  • updates dynamically during gameplay

Another example:

💰 Collected: ${this.coinsCollected}/${this.totalCoins}

This shows coin progress.


Example 4: File Paths

Strings are used for image paths.

src: path + "/images/projects/ocean/bg/reef.png"

Explanation

This string tells the game:

  • where images are stored
  • what sprite to load
  • what background to render

Example 5: Filtering Objects

Strings help search for specific game objects.

obj.spriteData?.id?.includes("EnemyElon")

Explanation

This checks whether:

  • an object’s ID contains text
  • the object is an enemy
  • collision logic should apply

Strings help categorize game entities.


Example 6: Combining Strings

My game combines strings with variables.

"Score: " + points

Explanation

This is called string concatenation.

It combines:

  • text
  • numerical values
  • dynamic game information

Example 7: Template Literals

My game also uses template literals.

`Goldfish${i}`

Explanation

This dynamically creates:

  • unique object IDs
  • numbered goldfish names
  • scalable object systems

Template literals make strings more flexible.


Why Strings Help My Game

Strings improved my project by:

  • displaying information to players
  • identifying game objects
  • organizing assets and files
  • supporting UI systems
  • enabling dynamic text updates

Without strings, the game could not communicate or organize information properly.