Script Writing Basics

An introduction to creating effective scripts with Valex

Getting Started with Scripting
The fundamentals you need to begin writing scripts

Scripting with Valex allows you to automate tasks, create custom tools, and enhance your experience. This guide will introduce you to the core concepts of scripting, proper syntax, and best practices to help you build your first scripts.

Syntax Basics

Valex scripts use standard Lua syntax with some additional libraries and functions. Here are the fundamental syntax elements you need to know:

Comments

-- This is a single line comment

--[[
  This is a multi-line comment.
  You can write multiple lines of text here.
]]

Variables

-- Local variables (preferred, limited to current scope)
local playerName = "User123"
local health = 100
local isAlive = true

-- Global variables (accessible from anywhere)
enemyCount = 5
gameVersion = "1.0.3"

Operators

-- Arithmetic operators
local sum = 10 + 5  -- Addition
local diff = 10 - 5  -- Subtraction
local product = 10 * 5  -- Multiplication
local quotient = 10 / 5  -- Division
local remainder = 10 % 3  -- Modulus (remainder)

-- Comparison operators
local isEqual = (value1 == value2)  -- Equal to
local notEqual = (value1 ~= value2)  -- Not equal to
local greater = (value1 > value2)  -- Greater than
local less = (value1 < value2)  -- Less than

Conditional Statements

-- If statement
if health > 50 then
    print("Player is healthy")
elseif health > 20 then
    print("Player is wounded")
else
    print("Player is critical")
end

Loops

-- Numeric for loop
for i = 1, 5 do
    print("Count: " .. i)
end

-- While loop
local counter = 0
while counter < 5 do
    print("Loop iteration: " .. counter)
    counter = counter + 1
end

-- Repeat until loop
local x = 0
repeat
    x = x + 1
    print("Repeat: " .. x)
until x >= 5

Next Steps

Practice

Start with small scripts and gradually build up your knowledge. Try modifying the examples to see how changes affect behavior.

Learn More

Once you're comfortable with basics, explore our Advanced Scripting guide to learn more complex techniques.

Get Inspired

Study and analyze example scripts in our community forums to get inspiration for your own projects.