Skip to main content

Statement sugar & expressions

Inside function bodies, TPScript expands a few high-level statements into C++ (raw C++ passes through verbatim). These keep beginner code short while generating idiomatic UE calls.

print​

print "Hello from TPScript";
print someVariable;

Expands to:

UE_LOG(LogTemp, Warning, TEXT("%s"), *something);

(A comma-separated list or expression is formatted accordingly.)

get_component​

get_component health: health_component

Gets a component already created as a member:

HealthType* health = FindComponentByClass<HealthType>();

cast​

cast pawn_ref: pawn from hit_actor
APawn* pawn_ref = Cast<APawn>(hit_actor);

spawn​

spawn enemy: enemy from spawn_location

Spawns an actor in the world:

AEnemy* enemy = GetWorld()->SpawnActor<AEnemy>(AEnemy::StaticClass(), spawn_location);

If no location is given, it uses the actor's own location.

bind_event​

bind_event OnDoorOpened to HandleDoorOpened
OnDoorOpened.AddDynamic(this, &AClass::HandleDoorOpened);

Raw C++ passes through​

Anything that isn't a recognized sugar statement is emitted verbatim, so you can always drop to full C++:

when_begin {
GetWorldTimerManager().SetTimer(ReloadTimer, this, &AMyWeapon::Reload, 1.5f, false);
}

High-level function calls​

You declare high-level functions, but you can call any C++ method directly:

run fire() {
GetWorld()->SpawnActor<AProjectile>(AProjectile::StaticClass(), MuzzleLocation, GetActorRotation());
}

Comments in bodies​

// comments inside bodies are preserved. Line comments that trail code (outside string literals) are handled specially so they don't get eaten.

Next: Advanced topics.