Unreal Game Engine – BluePrints – Variables and Datatypes

Unreal Game Engine – BluePrints – Variables and Datatypes

1. LEFT COLUMN> Content Browser> New> Blueprint> Actor> name it ‘MyBlueprint’, double click to open it.

2. MyBlueprint window> LEFT COLUMN> +Variable, nami it ‘MyFirstVar’

3. MyBlueprint window> LEFT COLUMN> Details> Variable Type> select the type between:

– bool : boolean
– byte
– int : integer numbers
– float : floating point numbers
– name
– string : alphanumeric characters
– text
– Vector : XYZ
– Rotator : rotation information
– Transform: translation, rotation, scale

+————-| on the right click over the red ‘Array’ icon to create an array.

4. DRAG AND DROP ‘MyFirstVar’ into EventGraph> Get> now the Variable Type is permanent and it can’t be changed.

By |Unreal Engine, Video Games Development|Commenti disabilitati su Unreal Game Engine – BluePrints – Variables and Datatypes

C++ – Functions

C++ – Functions

Functions allow to structure programs in segments of code to perform individual tasks.

Functions with type

Working samples:


// function example
#include <iostream>
using namespace std;

// integer - name of the function - data
int addition (int a, int b)
{
  int r;
  r=a+b;
  return r;
}

int main ()
{
  int z;
  z = addition (5,3);
  cout << "The result is " << z; // the result is 8
}


// function example
#include <iostream>
using namespace std;

int subtraction (int a, int b)
{
  int r;
  r=a-b;
  return r;
}

int main ()
{
  int x=5, y=3, z;
  z = subtraction (7,2);
  cout << "The first result is " << z << '\n';
  cout << "The second result is " << subtraction (7,2) << '\n';
  cout << "The third result is " << subtraction (x,y) << '\n';
  z= 4 + subtraction (x,y);
  cout << "The fourth result is " << z << '\n';
}

Functions with no type – void


// void function example
#include <iostream>
using namespace std;

void printmessage ()
{
  cout << "I'm a function!"; // it prints 'I'm a function!'
}

int main ()
{
  printmessage ();
}

Arguments passed by reference

// passing parameters by reference
#include <iostream>
using namespace std;

void duplicate (int& a, int& b, int& c)
{
  a*=2;
  b*=2;
  c*=2;
}

int main ()
{
  int x=1, y=3, z=7;
  duplicate (x, y, z);
  cout << "x=" << x << ", y=" << y << ", z=" << z;
  return 0;
}

The result:
x=2, y=6, z=14

By |C++, Video Games Development|Commenti disabilitati su C++ – Functions

C++ – For Statement

C++ – For Statement

Working samples:


// countdown using a for loop
#include <iostream>
using namespace std;

int main ()
{
  for (int n=10; n>0; n--) {
    cout << n << ", ";
  }
  cout << "liftoff!\n";
}

The result:

10, 9, 8, 7, 6, 5, 4, 3, 2, 1, liftoff!


// break loop example
#include <iostream>
using namespace std;

int main ()
{
  for (int n=10; n>0; n--)
  {
    cout << n << ", ";
    if (n==3)
    {
      cout << "countdown aborted!";
      break;
    }
  }
}

The result:
10, 9, 8, 7, 6, 5, 4, 3, countdown aborted!


// continue loop example
#include <iostream>
using namespace std;

int main ()
{
  for (int n=10; n>0; n--) {
    if (n==5) continue;
    cout << n << ", ";
  }
  cout << "liftoff!\n";
}

The result:
10, 9, 8, 7, 6, 4, 3, 2, 1, liftoff!

By |C++, Video Games Development|Commenti disabilitati su C++ – For Statement

C++ – Do While Statement

C++ – Do While Statement

Working sample:


// custom countdown using while
#include <iostream>
using namespace std;

int main ()
{
  int n = 10;

  while (n>0) {
    cout << n << ", ";
    --n;
  }

  cout << "liftoff!\n";
}

The result:

10, 9, 8, 7, 6, 5, 4, 3, 2, 1, liftoff!


// echo machine
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string str;
  do {
    cout << "Enter text: ";
    getline (cin,str);
    cout << "You entered: " << str << '\n';
  } while (str != "goodbye");
}

The result:

Enter text: hello
You entered: hello
Enter text: who’s there?
You entered: who’s there?
Enter text: goodbye
You entered: goodbye
Process returned 0

By |C++, Video Games Development|Commenti disabilitati su C++ – Do While Statement

C++ – Switch Statement

C++ – Switch Statement

Working samples:

...
switch (expression)
{
  case constant1:
     group-of-statements-1;
     break;
  case constant2:
     group-of-statements-2;
     break;
  .
  .
  .
  default:
     default-group-of-statements
}
...
By |C++, Video Games Development|Commenti disabilitati su C++ – Switch Statement