Skip to content

Latest commit

Β 

History

History
145 lines (114 loc) Β· 2.52 KB

File metadata and controls

145 lines (114 loc) Β· 2.52 KB

TechScript Language Cheat Sheet

A simple reference card for TechScript v2. Save this for quick lookups!


πŸ“€ Output & Input

say "Hello"               # Print text
say "Hi", name, "!"       # Print multiple values
say f"Hello {name}!"      # F-string (insert variable)
make name = ask "Name? "  # Read input from user

πŸ“¦ Variables

make x = 10              # Create variable
keep PI = 3.14159        # Create constant (can't change)
make name = "Alice"
make items = [1, 2, 3]   # List
make info = {"age": 25}  # Map/Dictionary

πŸ”€ Conditions

when x > 10 {
    say "Big"
} or when x == 10 {
    say "Exactly 10"
} else {
    say "Small"
}

πŸ” Loops

each item in [1, 2, 3] {
    say item
}

each i in 1..10 {    # Range 1 to 9
    say i
}

repeat x > 0 {       # While loop
    x -= 1
}

πŸ”§ Functions

build greet(name, greeting = "Hello") {
    say f"{greeting}, {name}!"
}

greet("Alice")             # Hello, Alice!
greet("Bob", "Hi")         # Hi, Bob!

πŸ—οΈ Classes

model Dog {
    build init(self, name) {
        self.name = name
    }
    build speak(self) {
        say f"{self.name} says Woof!"
    }
}

make rex = Dog("Rex")
rex.speak()

⚠️ Error Handling

attempt {
    # risky code here
} catch err {
    say f"Error: {err.message}"
}

🌐 Web (use web)

use web
make page = WebPage("Title")

page.style("body", { "background": "#111" })
page.script("function hello() { alert('Hi!'); }")

page.body([
    page.h1("My Page"),
    page.p("Some text"),
    page.button("Click", { "onclick": "hello()" })
])

page.run()           # Starts browser instantly!

πŸ“ Built-in Functions

Function What it does
len(x) Length of string/list
range(n) List 0 to n-1
type(x) Get type of value
int(x) Convert to integer
str(x) Convert to string
float(x) Convert to decimal
abs(x) Absolute value
round(x, n) Round to n places
max(a, b) Maximum value
min(a, b) Minimum value

πŸ”€ String Methods

"hello".upper()       # "HELLO"
"HELLO".lower()       # "hello"
"hello world".split() # ["hello", "world"]
"  hi  ".trim()       # "hi"
"hello".replace("l", "r") # "herro"
"hello".contains("ell")   # true

πŸ“‹ List Methods

make nums = [3, 1, 2]
nums.append(4)
nums.sort()
nums.reverse()
nums.map((x) => x * 2)
nums.filter((x) => x > 2)
nums.length