Appending Array in Godot

An array is a collection of one or more values of the same type. Each value is called an element of the array. The components of the array share the same variable name, but each part has its unique index number (also known as a subscript).

An array can be of any type, for example, int, float, char, etc.

Always remember arrays always start from their index value, and the index of the array is begun from 0 to n-1.

Suppose we want to access the 5th element of the array, then we will help us 4th element because arrays start from 0, and the array is always stored in contiguous memory locations. The number of elements and types of array identified by the subscript of array elements. The various types of Array that are provided by c as follows:-

  1. Single Dimensional Array
  2. Two dimensional Array
  3. Three dimensional Array
  4. Character Array or String

Single dimensional Array

A dimensional is used representing the elements of the array

for example

        int a[5]

The [] is used for dimensional or the subscript of the array that is generally used for declaring the elements of the array.

For Accessing the Element from the collection, we can use the Subscript of the Array like this

        a[3]=100

This will set the value of the 4th element of an array

So there is only the single bracket then it called the Single Dimensional Array

This is also called as the Single Dimensional array

Two Dimensional Arrays or matrix

The two-dimensional array is used for representing the elements of the array in the form of the rows and columns, and these are used for representing the matrix A two-dimensional array uses the two subscripts for declaring the elements of the Array Like this int a [3] [3]

Multidimensional or Three Dimensional Array:

The multidimensional array is used for representing the total number of tables of matrix A three-dimensional array is used when we want to make the two or more tables of the matrix elements for declaring the array element we can use the way like this

Int a [3][3][3]

This first 3 represents the total number of Tables, and the second 3 represents the total number of rows in each table, and the third 3 represents the total number of columns in the tables.

So this makes the 3 tables having the three rows and the three columns the primary and essential thing about the array that the elements are always stored in the contiguous in the memory of the computer.

Character Array of String

As an integer, the character is also in the Array. The array of characters is called the strings; they are generally used for representing the strings always remember that a string is terminated with the \o or null character.

There is the built-in string operation; the C language in the string provides those.h header file like

  • strLen: For getting the Length or total numbers of characters in a string
  • strconcat: This is used for joining the two strings, or this function is used for concatenating the two strings.
  • strRev: This function is used for obtaining the reverse of the string
  • strcmp: This function is used for comparing the Two strings, and it gives us the result as follows after comparing the two strings.

Open Godot Engine, then click on the script.

Code:

Screenshot:

Appending arrays & if-condition
Appending arrays & if-condition

Updated coded part:

If we press any function with the ctrl button, then we see the description and type of function like below we click on size () then the following description will open.

Appending arrays & if-condition

Could you scroll down to see more about it?

Complete Code:

Then we run the code the output will be like this:

Appending arrays & if-condition
Appending arrays & if-condition
Appending arrays & if-condition
Appending arrays & if-condition

After this question and answers, the story will be generated below:

Appending arrays & if-condition

Now we can change some DisplayText also as our wish as we do: And at the end, we should add a Plus (+) sign to add the display text into it.

These lines are the added lines.

Appending arrays & if-condition
Appending arrays & if-condition

Updated code is:

Output after adding lines:

Appending arrays & if-condition
Appending arrays & if-condition
Appending arrays & if-condition
Appending arrays & if-condition

And here the story is ready.

Appending arrays & if-condition




Latest Courses