Powerlang Docs
  • Welcome!
  • Beginner's Guide
    • Syntax
    • Directives
    • Environment
    • Special types
    • Functions
    • Tables
    • Loops
    • Conditions
    • Events
    • Libraries
    • Comments and Flags
  • Creating a Game
    • Project Introduction: Potato Rush
    • Creating the main game loop
    • Creating potatoes
    • Keeping track of score
  • Libraries
    • Special Types
      • BrickColor
      • CFrame
      • Color3
      • Instance
      • NumberRange
      • UDim2
      • Vector2
      • Vector3
    • Services
      • DataStore
      • Debris
      • Mouse
      • Pathfinding
      • PhysicsService
      • Players
      • Ray
      • TweenService
    • compiler
    • math
    • os
    • string
    • table
    • retrostudio
  • Advanced Information
    • Instance Functions
    • Global Functions
    • Multithreading
    • Compiler Library
Powered by GitBook
On this page
  1. Beginner's Guide

Syntax

Now that you've been introduced to the language, let's discuss the syntax.

In Powerlang, the syntax defines the rules for how code is written and structured. Understanding these rules is crucial for writing functional and efficient programs.

All code in Powerlang consists of equations and directives.

An equation is a sequence of operators, table indexes, and function calls. An equation's result can be stored in one or multiple variables for later use. For instance, this equation would calculate 2 + 2 * 2 (6, as multiplication takes precedence over addition) and store it in a variable Result:

Result = 2 + 2 * 2

A directive is an instruction that controls how the program should behave or proceed. While equations handle calculations and data manipulation, directives control the flow of the program, guiding it to repeat tasks, make decisions, or respond to events. Here's an example of using the for directive to print numbers 1 to 10:

for i = 1, 10 {
    print(i)
}

Unlike in Lua, directive content is enclosed in curly braces ({}) instead of do/end.

Directives can also be used to create functions. A function is a reusable block of code designed to perform a specific task. It can take arguments, process them, and optionally return an output. The purpose of a function is to break down complex tasks into smaller, manageable parts and to promote code reusability. We'll dive deeper into how they work later. On the next page we will take a look at the available directives and what they do.

PreviousWelcome!NextDirectives

Last updated 8 months ago