A simple reference card for TechScript v2. Save this for quick lookups!
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
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
when x > 10 {
say "Big"
} or when x == 10 {
say "Exactly 10"
} else {
say "Small"
}
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
}
build greet(name, greeting = "Hello") {
say f"{greeting}, {name}!"
}
greet("Alice") # Hello, Alice!
greet("Bob", "Hi") # Hi, Bob!
model Dog {
build init(self, name) {
self.name = name
}
build speak(self) {
say f"{self.name} says Woof!"
}
}
make rex = Dog("Rex")
rex.speak()
attempt {
# risky code here
} catch err {
say f"Error: {err.message}"
}
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!
| 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 |
"hello".upper() # "HELLO"
"HELLO".lower() # "hello"
"hello world".split() # ["hello", "world"]
" hi ".trim() # "hi"
"hello".replace("l", "r") # "herro"
"hello".contains("ell") # true
make nums = [3, 1, 2]
nums.append(4)
nums.sort()
nums.reverse()
nums.map((x) => x * 2)
nums.filter((x) => x > 2)
nums.length