Starlight Language Tutorial

Welcome! This tutorial guides you through the Starlight Programming Language (SL), including CLI usage, interactive scripting, and advanced programming examples.

Highlights: Learn to create interactive scripts, manage data, build games, handle async operations, and develop real-world applications with SL.

Getting Started

Installation: Install the Starlight CLI to run `.sl` scripts locally.

Running Scripts: Use starlight your_script.sl to execute programs from the command line.

1. Variables

Use let or define to create variables:

let a = 10
define b = "hello"
sldeploy(a, b)
a: 10 b: hello

2. Arrays

Create arrays and use built-in functions:

let arr = [1,2,3,4,5]
let doubled = map(arr, x => x * 2)
sldeploy(doubled)
[2, 4, 6, 8, 10]

3. Loops

let sum = 0
for i in range(1, 6) {
    sum += i
}
sldeploy(sum)
15

4. Functions

define square = x => x * x
let result = square(5)
sldeploy(result)
25

5. Objects

let person = {
    name: "Alice",
    age: 20,
    greet: () => "Hello"
}
sldeploy(person)
{name: "Alice", age: 20, greet: }

6. Built-in functions

let nums = [1,2,3,4,5]
let evens = filter(nums, x => x % 2 == 0)
sldeploy(evens)
[2, 4]

7. Reduce

let nums = [1, 2, 3, 4, 5]
let total = reduce(nums, (acc, x) => acc + x, 0)
sldeploy(total)
15

8. Keys and Values

let obj = {a: 1, b: 2, c: 3}
sldeploy(keys(obj))
sldeploy(values(obj))
["a", "b", "c"] [1, 2, 3]

9. Range

let r1 = range(5)      // 0..4
let r2 = range(2, 6)   // 2..5
let r3 = range(10, 0, -2) // 10, 8, 6, 4, 2
sldeploy(r1)
sldeploy(r2)
sldeploy(r3)
[0, 1, 2, 3, 4] [2, 3, 4, 5] [10, 8, 6, 4, 2]

10. Ask User Input

let name = ask("What is your name?")
sldeploy("Hello, " + name)
// If user types "Alice" // Hello, Alice

11. Num Conversion

sldeploy(num("123"))   // 123
sldeploy(num(true))      // 1
sldeploy(num(false))     // 0
sldeploy(num([1,2,3]))   // 3
123 1 0 3

12. Str Conversion

sldeploy(str(123))    // "123"
sldeploy(str(true))   // "true"
sldeploy(str([1,2,3])) // "1,2,3"
"123" "true" "1,2,3"

13. Sleep / Delay

print("Start")
await sleep(1000)  // wait 1 second
sldeploy("End")
Start (wait 1 second) End

14. Fetch JSON

let data = await get("https://jsonplaceholder.typicode.com/todos/1")
sldeploy(data)
{userId: 1, id: 1, title: "delectus aut autem", completed: false}

15. Advanced Loops (for in / for let in)

Starlight provides two loop forms: for in and for let in. Arrays are immutable and do not support .push(). Use array concatenation instead.

15.1 for let in (Scoped variable)

let names = ["Ana", "Mark", "Lena"]

for let n in names {
  sldeploy("Hello " + n)
}
Hello Ana Hello Mark Hello Lena

15.2 Filtering data with continue

let numbers = [3, -1, 0, 7, 9]
let positives = []

for let x in numbers {
  if x <= 0 {
    continue
  }
  positives = positives + [x]
}

sldeploy(positives)
[3, 7, 9]

15.3 Iterating objects with nested loops

let scores = {
  math: [90, 85],
  physics: [92, 80]
}

for let subject in scores {
  let total = 0
  let count = 0

  for let s in scores[subject] {
    total += s
    count += 1
  }

  let avg = total / count
  sldeploy(subject + " avg = " + avg)
}
math avg = 87.5 physics avg = 86

15.4 Real-world example: filter adults

let users = [
  { name: "Ana", age: 17 },
  { name: "Mark", age: 22 },
  { name: "Lena", age: 15 },
  { name: "Tom", age: 30 }
]

let adults = []

for let u in users {
  if u.age < 18 {
    continue
  }
  adults = adults + [u.name]
}

sldeploy("Adult users:")
for let name in adults {
  sldeploy("- " + name)
}
Adult users: - Mark - Tom

16.1 Log Analyzer (Real-World CLI Tool)

let logs = [
  "INFO: Server started",
  "ERROR: Database connection failed",
  "WARN: Memory usage high",
  "ERROR: Timeout while querying",
  "INFO: Request handled",
  "ERROR: Database connection failed"
]

let errors = {}

for let line in logs {
  if not line.startsWith("ERROR") {
    continue
  }

  let msg = line.replace("ERROR: ", "")

  if not errors[msg] {
    errors[msg] = 0
  }

  errors[msg] += 1
}

sldeploy("Error summary:")
for let key in keys(errors) {
  sldeploy(key + " -> " + errors[key])
}
Error summary:
Database connection failed -> 2
Timeout while querying -> 1

16.2 Student Grade System

let students = [
  { name: "Ana", grades: [90, 85, 92] },
  { name: "Mark", grades: [55, 60, 58] },
  { name: "Lena", grades: [78, 80, 82] }
]

for let s in students {
  let sum = 0

  for let g in s.grades {
    sum += g
  }

  let avg = sum / len(s.grades)

  if avg < 60 {
    sldeploy(s.name + " FAILED (" + avg + ")")
  } else {
    sldeploy(s.name + " PASSED (" + avg + ")")
  }
}
Ana PASSED (89)
Mark FAILED (57.666666666666664)
Lena PASSED (80)

16.3 Expense Tracker (Finance)

let expenses = [
  { category: "Food", amount: 25 },
  { category: "Transport", amount: 10 },
  { category: "Food", amount: 15 },
  { category: "Entertainment", amount: 40 }
]

let totals = {}

for let e in expenses {
  if not totals[e.category] {
    totals[e.category] = 0
  }
  totals[e.category] += e.amount
}

sldeploy("Expense report:")
for let c in keys(totals) {
  sldeploy(c + ": $" + totals[c])
}
Expense report:
Food: $40
Transport: $10
Entertainment: $40

16.4 Password Strength Checker

let passwords = ["hello", "Pa55word", "123456", "Str0ng!Pass"]

for let p in passwords {
  let score = 0

  if p.len >= 8 { score += 1 }
  if p.match("[A-Z]") { score += 1 }
  if p.match("[0-9]") { score += 1 }
  if p.match("[^a-zA-Z0-9]") { score += 1 }

  sldeploy(p + " -> strength " + score + "/4")
}
hello -> strength 1/4
Pa55word -> strength 4/4
123456 -> strength 2/4
Str0ng!Pass -> strength 4/4

16.5 Chat Command Parser

let messages = [
  "/help",
  "/ban user123",
  "hello everyone",
  "/kick troll"
]

for let msg in messages {
  if not msg.startsWith("/") {
    continue
  }

  let parts = msg.split(" ")
  let command = parts[0]

  if command == "/help" {
    sldeploy("Show help menu")
  }

  if command == "/ban" {
    sldeploy("Ban user " + parts[1])
  }

  if command == "/kick" {
    sldeploy("Kick user " + parts[1])
  }
}
Show help menu
Ban user user123
Kick user troll

16.6 Game Logic: Inventory System

let inventory = [
  { name: "Sword", damage: 10 },
  { name: "Dagger", damage: 4 },
  { name: "Axe", damage: 12 }
]

let best = inventory[0]

for let item in inventory {
  if item.damage > best.damage {
    best = item
  }
}

sldeploy("Best weapon: " + best.name)
Best weapon: Axe

16.7 Mini Data Pipeline

let raw = [" 12 ", " 7", "bad", "30", ""]

let cleaned = []

for let x in raw {
  let v = num(x.trim())
  if isNaN(v) {
    continue
  }
  cleaned = cleaned + [v]
}

let total = 0
for let n in cleaned {
  total += n
}

sldeploy("Numbers: " + cleaned)
sldeploy("Sum: " + total)
Numbers: 12,7,30
Sum: 49

16.8 Random Quote Generator

let quotes = [
  "Code is poetry.",
  "Fix the cause, not the symptom.",
  "Simplicity is power.",
  "Programs must be read by humans."
]

let index = random(0, len(quotes))
sldeploy(quotes[index])
(Code will print one random quote from the array)

16.9 API Data Filter

let todos = await get("https://jsonplaceholder.typicode.com/todos")

let completed = []

for let t in todos {
  if t.completed {
    completed = completed + [t.title]
  }
}

sldeploy("Completed tasks:")
for let title in completed {
  sldeploy("- " + title)
}
Completed tasks:
- delectus aut autem
- quis ut nam facilis et officia qui
- fugiat veniam minus
...

17.1 Advanced: Multi-Level Log Analyzer

let logs = [
  { date: "2026-01-01", message: "ERROR: Database failed" },
  { date: "2026-01-01", message: "WARN: Memory high" },
  { date: "2026-01-02", message: "ERROR: Timeout" },
  { date: "2026-01-02", message: "INFO: Task done" },
  { date: "2026-01-02", message: "ERROR: Database failed" }
]

let summary = {}

for let log in logs {
  let type = log.message.split(":")[0]
  let day = log.date

  if not summary[day] { summary[day] = {} }
  if not summary[day][type] { summary[day][type] = 0 }

  summary[day][type] += 1
}

sldeploy("Daily log summary:")
for let day in keys(summary) {
  sldeploy(day + ":")
  for let t in keys(summary[day]) {
    sldeploy("  " + t + " -> " + summary[day][t])
  }
}
Daily log summary:
2026-01-01:
  ERROR -> 1
  WARN -> 1
2026-01-02:
  ERROR -> 2
  INFO -> 1

17.2 Async: Fetch and Filter API Data

let posts = await get("https://jsonplaceholder.typicode.com/posts")

let userPosts = []

for let post in posts {
  if post.userId == 1 {
    userPosts = userPosts + [post.title]
  }
}

sldeploy("User 1 posts:")
for let title in userPosts {
  sldeploy("- " + title)
}
User 1 posts:
- (titles from userId 1)
- ...

17.3 Functional: Map, Filter, Reduce

let items = [
  { name: "Laptop", price: 1200, discount: 200 },
  { name: "Mouse", price: 25, discount: 5 },
  { name: "Keyboard", price: 45, discount: 10 },
  { name: "Monitor", price: 300, discount: 50 }
]

let discounted = await filter(items, i => i.price - i.discount > 20)

let total = await reduce(discounted, (acc, i) => acc + (i.price - i.discount), 0)

sldeploy("Total price of items over $20 after discount: $" + total)
Total price of items over $20 after discount: $1490

17.4 Game Logic: Turn-Based Battle

let hero = { name: "Hero", hp: 50, attack: 10 }
let monster = { name: "Monster", hp: 40, attack: 8 }

while hero.hp > 0 and monster.hp > 0 {
  monster.hp -= hero.attack
  sldeploy(hero.name + " attacks " + monster.name + " -> " + monster.hp + " HP left")
  if monster.hp <= 0 { break }

  hero.hp -= monster.attack
  sldeploy(monster.name + " attacks " + hero.name + " -> " + hero.hp + " HP left")
}

if hero.hp > 0 {
  sldeploy(hero.name + " wins!")
} else {
  sldeploy(monster.name + " wins!")
}
Hero attacks Monster -> 30 HP left
Monster attacks Hero -> 42 HP left
Hero attacks Monster -> 20 HP left
Monster attacks Hero -> 34 HP left
...
Hero wins!

17.5 Data Analysis: Password Strength Stats

let passwords = ["hello", "Pa55word", "123456", "Str0ng!Pass", "Weak1"]

let stats = { strong: 0, weak: 0 }

for let p in passwords {
  let score = 0
  if p.len >= 8 { score += 1 }
  if p.match("[A-Z]") { score += 1 }
  if p.match("[0-9]") { score += 1 }
  if p.match("[^a-zA-Z0-9]") { score += 1 }

  if score >= 3 { stats.strong += 1 } else { stats.weak += 1 }
}

sldeploy("Password strength stats:")
sldeploy("Strong: " + stats.strong)
sldeploy("Weak: " + stats.weak)
Password strength stats:
Strong: 2
Weak: 3

18. Interactive Survey – Ask User Input

# interactive_survey.sl

let name = ask("What is your name?")
let age = ask("How old are you?")
let favoriteColor = ask("What is your favorite color?")

sldeploy("Survey Results:")
sldeploy("Name: " + name)
sldeploy("Age: " + age)
sldeploy("Favorite color: " + favoriteColor)

if num(age) >= 18 {
  sldeploy("You are an adult.")
} else {
  sldeploy("You are a minor.")
}

Features: ask input, conditional branching, string concatenation, numeric conversion.

19. Async Weather Fetcher

# weather_fetch.sl

let city = ask("Enter a city name:")
let weatherData = await get("https://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=YOUR_API_KEY&units=metric")

sldeploy("Weather in " + city + ":")
sldeploy("Temperature: " + weatherData.main.temp + "°C")
sldeploy("Condition: " + weatherData.weather[0].description)

Features: Async API request, await, JSON access, dynamic string interpolation.

20. Turn-Based Battle Game

# battle_game.sl

let hero = { name: ask("Enter hero name:"), hp: 50, attack: 10 }
let monster = { name: "Goblin", hp: 30, attack: 8 }

while hero.hp > 0 and monster.hp > 0 {
  let action = ask("Choose action: attack or heal").toLowerCase()

  if action == "attack" {
    monster.hp -= hero.attack
    sldeploy(hero.name + " attacks " + monster.name + " -> " + monster.hp + " HP left")
  } else if action == "heal" {
    hero.hp += 5
    sldeploy(hero.name + " heals -> " + hero.hp + " HP")
  } else {
    sldeploy("Invalid action!")
  }

  if monster.hp <= 0 { break }

  hero.hp -= monster.attack
  sldeploy(monster.name + " attacks " + hero.name + " -> " + hero.hp + " HP left")
}

if hero.hp > 0 {
  sldeploy(hero.name + " wins!")
} else {
  sldeploy(monster.name + " wins!")
}

Features: Interactive game, while loops, branching, dynamic stats.

21. Password Strength Checker – Interactive

# password_checker.sl

let passwords = []

while true {
  let pwd = ask("Enter a password (or 'done' to finish):")
  if pwd.toLowerCase() == "done" { break }
  passwords = passwords + [pwd]
}

let stats = { strong: 0, weak: 0 }

for let p in passwords {
  let score = 0
  if p.len >= 8 { score += 1 }
  if p.match("[A-Z]") { score += 1 }
  if p.match("[0-9]") { score += 1 }
  if p.match("[^a-zA-Z0-9]") { score += 1 }

  if score >= 3 { stats.strong += 1 } else { stats.weak += 1 }
}

sldeploy("Password strength stats:")
sldeploy("Strong: " + stats.strong)
sldeploy("Weak: " + stats.weak)

Features: ask loop, arrays, regex matching, scoring logic.

22. Async Todo List Filter

# todos_filter.sl

let userId = num(ask("Enter user ID to filter tasks:"))

let todos = await get("https://jsonplaceholder.typicode.com/todos")
let completed = []

for let t in todos {
  if t.userId == userId and t.completed {
    completed = completed + [t.title]
  }
}

sldeploy("Completed tasks for user " + userId + ":")
for let title in completed {
  sldeploy("- " + title)
}

Features: Async fetching, filtering, interactive input.

23. Multi-Battle Fixed

# multi_battle_fixed.sl

let numPlayers = num(ask("How many heroes?"))
let heroes = []

for let i in range(0, numPlayers) {
  let name = ask("Enter hero " + (i + 1) + " name:")
  heroes = heroes + [{ name: name, hp: 50, attack: 8 + i }]
}

let monster = { name: "Dragon", hp: 100, attack: 12 }

while monster.hp > 0 and len(heroes.filter(h => h.hp > 0)) > 0 {
  for let h in heroes {
    if h.hp <= 0 { continue }
    monster.hp -= h.attack
    sldeploy(h.name + " attacks " + monster.name + " -> " + monster.hp + " HP left")
    if monster.hp <= 0 { break }
  }

  if monster.hp <= 0 { break }

  let alive = heroes.filter(h => h.hp > 0)
  if len(alive) > 0 {
    let target = alive[0]
    target.hp -= monster.attack
    sldeploy(monster.name + " attacks " + target.name + " -> " + target.hp + " HP left")
  }
}

if monster.hp <= 0 { 
  sldeploy("Heroes win!") 
} else { 
  sldeploy(monster.name + " wins!") 
}

Features: Multi-character battle, loops, filtering, interactive input.

24. Real-Time Stock Analyzer (Async + Interactive)

# stock_analyzer.sl

let tickers = ask("Enter stock symbols separated by commas:").split(",")

let stocks = []
for let t in tickers {
  let data = await get("https://api.example.com/stocks/" + t.trim())
  stocks = stocks + [{ symbol: t.trim(), price: data.price, change: data.change }]
}

let winners = stocks.filter(s => s.change > 0)
let losers = stocks.filter(s => s.change <= 0)

sldeploy("Winners:")
for let s in winners { 
  sldeploy(s.symbol + " -> $" + s.price + " (+" + s.change + "%)") 
}

sldeploy("Losers:")
for let s in losers { 
  sldeploy(s.symbol + " -> $" + s.price + " (" + s.change + "%)") 
}

Features: Async fetching, filter, string processing, interactive input.

25. Interactive Quiz with Scoring

# quiz.sl

let questions = [
  { q: "2 + 2 = ?", a: "4" },
  { q: "Capital of France?", a: "Paris" },
  { q: "5 * 6 = ?", a: "30" }
]

let score = 0

for let i in range(0, len(questions)) {
  let answer = ask(questions[i].q)
  if answer.trim().toLowerCase() == questions[i].a.toLowerCase() {
    sldeploy("Correct!")
    score += 1
  } else {
    sldeploy("Wrong! Answer: " + questions[i].a)
  }
}

sldeploy("Your total score: " + score + "/" + len(questions))

Features: ask, loops, conditional scoring, string comparison.

26. Mini Functional Pipeline: Shopping Cart Total

# shopping_cart.sl

let cart = [
  { item: "Laptop", price: 1200, qty: 1 },
  { item: "Mouse", price: 25, qty: 2 },
  { item: "Keyboard", price: 45, qty: 1 },
  { item: "Monitor", price: 300, qty: 1 }
]

let total = cart
  .map(c => c.price * c.qty)
  .reduce((acc, v) => acc + v, 0)

sldeploy("Total cart value: $" + total)

Features: map, reduce, functional programming style.

27. Interactive To-Do Manager

# todo_manager.sl

let todos = []

while true {
  let cmd = ask("Command (add/list/complete/exit):").toLowerCase()
  if cmd == "exit" { break }
  if cmd == "add" {
    let task = ask("Task description:")
    todos = todos + [{ task, done: false }]
  }
  if cmd == "list" {
    sldeploy("To-Do List:")
    for let i in range(0, len(todos)) {
      let t = todos[i]
      sldeploy((i+1) + ". [" + (t.done ? "x" : " ") + "] " + t.task)
    }
  }
  if cmd == "complete" {
    let idx = num(ask("Enter task number to mark complete:")) - 1
    if idx >= 0 and idx < len(todos) { todos[idx].done = true }
  }
}
sldeploy("Exiting To-Do Manager.")

Features: Interactive loop, dynamic arrays, object mutation.

28. Async Random Joke Fetcher

# jokes_fetch.sl

let count = num(ask("How many jokes do you want?"))

for let i in range(0, count) {
  let joke = await get("https://official-joke-api.appspot.com/random_joke")
  sldeploy("Joke " + (i+1) + ": " + joke.setup + " ... " + joke.punchline)
}

Features: Async API calls, loops, interactive input, string formatting.

29. Dungeon Exploration Game

# dungeon_game.sl

let player = { name: ask("Hero name:"), hp: 30, attack: 8 }
let dungeon = [
  { name: "Goblin", hp: 12, attack: 4 },
  { name: "Orc", hp: 20, attack: 6 },
  { name: "Dragon", hp: 40, attack: 12 }
]

for let room in dungeon {
  sldeploy("You encounter a " + room.name + "!")
  
  while player.hp > 0 and room.hp > 0 {
    let action = ask("Attack or heal?").toLowerCase()
    if action == "attack" {
      room.hp -= player.attack
      sldeploy("You hit " + room.name + " -> " + room.hp + " HP left")
    } else if action == "heal" {
      player.hp += 5
      sldeploy("You heal -> " + player.hp + " HP")
    } else {
      sldeploy("Invalid action!")
    }

    if room.hp <= 0 { break }

    player.hp -= room.attack
    sldeploy(room.name + " hits you -> " + player.hp + " HP left")
  }

  if player.hp <= 0 { sldeploy("You died! Game over."); break }
  else { sldeploy("You defeated " + room.name + "!") }
}

if player.hp > 0 { sldeploy("Congratulations! You cleared the dungeon.") }

Features: Interactive RPG, loops, branching, dynamic stats.

30. Advanced Interactive Bank System

Concepts:


# bank_system.sl

let balance = 0

sldeploy("Welcome to SL Bank")

while true {
  let cmd = ask("Choose: deposit / withdraw / balance / exit")

  if cmd == "exit" {
    break
  }

  if cmd == "deposit" {
    let amount = num(ask("Enter amount to deposit:"))
    if amount > 0 {
      balance += amount
      sldeploy("Deposited: $" + amount)
    } else {
      sldeploy("Invalid amount")
    }
  }

  if cmd == "withdraw" {
    let amount = num(ask("Enter amount to withdraw:"))
    if amount > 0 and amount <= balance {
      balance -= amount
      sldeploy("Withdrawn: $" + amount)
    } else {
      sldeploy("Insufficient funds or invalid amount")
    }
  }

  if cmd == "balance" {
    sldeploy("Current balance: $" + balance)
  }
}

sldeploy("Thank you for using SL Bank")

31. Advanced File Log Simulator

Concepts:


# log_simulator.sl

let logs = [
  "INFO: App started",
  "ERROR: Disk full",
  "WARN: High CPU usage",
  "ERROR: Disk full",
  "INFO: User login",
  "WARN: Memory low"
]

let stats = {}

for let line in logs {
  let parts = line.split(":")
  let level = parts[0]

  if not stats[level] {
    stats[level] = 0
  }

  stats[level] += 1
}

sldeploy("Log statistics:")
for let key in keys(stats) {
  sldeploy(key + " -> " + stats[key])
}
INFO -> 2
ERROR -> 2
WARN -> 2

32. Advanced Interactive Voting System

Concepts:


# voting_system.sl

let candidates = []
let votes = {}

let count = num(ask("How many candidates?"))

for let i in range(0, count) {
  let name = ask("Candidate " + (i + 1) + " name:")
  candidates = candidates + [name]
  votes[name] = 0
}

let voters = num(ask("How many voters?"))

for let i in range(0, voters) {
  sldeploy("Candidates:")
  for let c in candidates {
    sldeploy("- " + c)
  }

  let choice = ask("Vote by typing candidate name:")
  if votes[choice] != null {
    votes[choice] += 1
  } else {
    sldeploy("Invalid vote")
  }
}

let winner = candidates[0]

for let c in candidates {
  if votes[c] > votes[winner] {
    winner = c
  }
}

sldeploy("Election Results:")
for let c in candidates {
  sldeploy(c + " -> " + votes[c])
}

sldeploy("Winner: " + winner)

33. Advanced: Safe Banking Transaction (do / track)

# safe_bank_transaction.sl

let balance = 100

sldeploy("Initial balance: $" + balance)

do {
  let action = ask("Choose action: deposit or withdraw")

  if action != "deposit" and action != "withdraw" {
    error("Invalid action selected")
  }

  let amount = num(ask("Enter amount:"))

  if amount <= 0 {
    error("Amount must be greater than zero")
  }

  if action == "withdraw" {
    if amount > balance {
      error("Insufficient funds")
    }
    balance -= amount
  }

  if action == "deposit" {
    balance += amount
  }

  sldeploy("Transaction successful")
  sldeploy("New balance: $" + balance)
}
track {
  sldeploy("Transaction failed!")
  sldeploy("Reason: " + error.message)
  sldeploy("Balance unchanged: $" + balance)
}

sldeploy("Program finished safely.")
Initial balance: $100 Transaction successful New balance: $150 —or— Transaction failed! Reason: Insufficient funds Balance unchanged: $100

34. Advanced Async Error Handling: API Safe Fetch

# api_safe_fetch.sl

let data = null

do {
  sldeploy("Fetching data...")
  data = await get("https://api.example.com/data")

  if data == null {
    error("API returned no data")
  }

  sldeploy("Data fetched successfully")
}
track {
  sldeploy("Fetch failed")
  sldeploy("Using fallback data")
  data = { status: "offline", items: [] }
}

sldeploy("Final data status: " + data.status)
Fetching data... Fetch failed Using fallback data Final data status: offline

35.1 Advanced System: Bank Account Management

# bank_system.sl

let balance = 0

sldeploy("Welcome to SL Bank")

while true {
  let cmd = ask("Choose: deposit / withdraw / balance / exit")

  if cmd == "exit" { break }

  if cmd == "deposit" {
    let amount = num(ask("Enter amount:"))
    if amount > 0 {
      balance += amount
      sldeploy("Deposited $" + amount)
    } else {
      sldeploy("Invalid amount")
    }
  }

  if cmd == "withdraw" {
    let amount = num(ask("Enter amount:"))
    if amount > 0 and amount <= balance {
      balance -= amount
      sldeploy("Withdrawn $" + amount)
    } else {
      sldeploy("Insufficient funds")
    }
  }

  if cmd == "balance" {
    sldeploy("Current balance: $" + balance)
  }
}

sldeploy("Session ended")
Deposit and withdrawal handled Balance validated Session closed safely

35.2 Advanced System: Secure ATM with PIN Validation

# atm_system.sl

let pin = "1234"
let balance = 500
let attempts = 0

sldeploy("Welcome to SL Secure ATM")

while attempts < 3 {
  let entered = ask("Enter PIN:")

  if entered == pin {
    sldeploy("Access granted")
    break
  }

  attempts += 1
  sldeploy("Incorrect PIN")
}

if attempts == 3 {
  sldeploy("Card blocked")
  return
}

while true {
  let cmd = ask("withdraw / deposit / balance / exit")

  if cmd == "exit" { break }

  if cmd == "balance" {
    sldeploy("Balance: $" + balance)
  }

  if cmd == "deposit" {
    let amt = num(ask("Amount:"))
    if amt > 0 {
      balance += amt
      sldeploy("Deposited $" + amt)
    }
  }

  if cmd == "withdraw" {
    let amt = num(ask("Amount:"))
    if amt > 0 and amt <= balance {
      balance -= amt
      sldeploy("Withdrawn $" + amt)
    } else {
      sldeploy("Invalid transaction")
    }
  }
}

sldeploy("ATM session ended")
PIN protected access Limited attempts Secure transactions

35.3 Advanced Simulation: Turn-Based Queue Combat System

# turn_queue.sl

let players = [
  { name: "Knight", hp: 30 },
  { name: "Mage", hp: 20 },
  { name: "Rogue", hp: 25 }
]

let turn = 0

while len(players) > 1 {
  let current = players[turn % len(players)]
  sldeploy("Turn: " + current.name)

  let action = ask("Attack or skip?")

  if action == "attack" {
    let targetIndex = (turn + 1) % len(players)
    let target = players[targetIndex]

    target.hp -= 5
    sldeploy(current.name + " attacks " + target.name)

    if target.hp <= 0 {
      sldeploy(target.name + " is defeated")
      players = players.filter(p => p.hp > 0)
      turn = turn % len(players)
    }
  }

  turn += 1
}

sldeploy("Winner: " + players[0].name)
Fair turn rotation Player elimination handled Winner declared correctly

35.4 Advanced Analytics: Performance Score Aggregator

# performance_analyzer.sl

let scores = []

while true {
  let cmd = ask("add / report / exit")

  if cmd == "exit" { break }

  if cmd == "add" {
    let name = ask("Name:")
    let score = num(ask("Score:"))
    scores = scores + [{ name: name, score: score }]
  }

  if cmd == "report" {
    let total = 0
    let max = 0

    for let s in scores {
      total += s.score
      if s.score > max { max = s.score }
    }

    if len(scores) > 0 {
      sldeploy("Average: " + (total / len(scores)))
      sldeploy("Highest score: " + max)
    }
  }
}
Scores collected Statistics calculated Performance insights shown

35.5 Advanced Workflow: Approval & Review System

# approval_system.sl

let requests = []

while true {
  let cmd = ask("submit / review / list / exit")

  if cmd == "exit" { break }

  if cmd == "submit" {
    let title = ask("Request title:")
    requests = requests + [{ title: title, status: "pending" }]
  }

  if cmd == "review" {
    let title = ask("Request title:")
    let decision = ask("approve / reject:")

    for let r in requests {
      if r.title == title {
        r.status = decision
      }
    }
  }

  if cmd == "list" {
    sldeploy("Requests:")
    for let r in requests {
      sldeploy(r.title + " [" + r.status + "]")
    }
  }
}
Requests submitted Approval workflow enforced Statuses tracked

36. Smart Recommendation Engine (Rules + Scoring)

# recommendation_engine.sl

let users = [
  { name: "Ana", interests: ["music", "art"] },
  { name: "Mark", interests: ["sports", "fitness"] },
  { name: "Lena", interests: ["music", "sports"] }
]

let content = [
  { title: "Rock Concert", tag: "music" },
  { title: "Art Exhibition", tag: "art" },
  { title: "Football Match", tag: "sports" },
  { title: "Gym Training", tag: "fitness" }
]

for let u in users {
  sldeploy("Recommendations for " + u.name + ":")
  for let c in content {
    for let i in u.interests {
      if c.tag == i {
        sldeploy("- " + c.title)
      }
    }
  }
}

37. Real-World Scheduler (Conflict Detection)

# scheduler.sl

let events = []

while true {
  let cmd = ask("add / list / exit")

  if cmd == "exit" { break }

  if cmd == "add" {
    let name = ask("Event name:")
    let time = ask("Time (e.g. 10:00):")

    let conflict = false
    for let e in events {
      if e.time == time { conflict = true }
    }

    if conflict {
      sldeploy("Time conflict detected!")
    } else {
      events = events + [{ name: name, time: time }]
      sldeploy("Event scheduled")
    }
  }

  if cmd == "list" {
    sldeploy("Schedule:")
    for let e in events {
      sldeploy(e.time + " -> " + e.name)
    }
  }
}

38. AI-Style Decision Tree (Advanced Logic)

# decision_tree.sl

let score = 0

let q1 = ask("Do you like coding? (yes/no)")
if q1 == "yes" { score += 2 }

let q2 = ask("Do you enjoy problem solving? (yes/no)")
if q2 == "yes" { score += 2 }

let q3 = ask("Do you like math? (yes/no)")
if q3 == "yes" { score += 1 }

if score >= 4 {
  sldeploy("You should be a Software Engineer")
} else if score >= 2 {
  sldeploy("You should explore Tech roles")
} else {
  sldeploy("Creative fields may suit you")
}

39. Multiplayer Economy Simulator

# economy_simulator.sl

let players = [
  { name: "Alice", money: 100 },
  { name: "Bob", money: 100 }
]

for let round in range(1, 6) {
  sldeploy("Round " + round)
  for let p in players {
    let income = 10
    let expense = 5
    p.money += income - expense
    sldeploy(p.name + " balance: $" + p.money)
  }
}

40. Access Control System (Roles & Permissions)

# access_control.sl

let users = [
  { name: "Admin", role: "admin" },
  { name: "Guest", role: "guest" }
]

for let u in users {
  sldeploy("User: " + u.name)
  if u.role == "admin" {
    sldeploy("Access: read, write, delete")
  }
  if u.role == "guest" {
    sldeploy("Access: read only")
  }
}

41. Strategy Game: Resource Gathering

# resource_game.sl

let resources = { wood: 0, stone: 0 }

for let day in range(1, 6) {
  resources.wood += 3
  resources.stone += 2

  sldeploy(
    "Day " + day +
    " | Wood: " + resources.wood +
    " | Stone: " + resources.stone
  )
}

42. Fraud Detection Rules Engine

# fraud_detection.sl

let transactions = [
  { user: "Ana", amount: 50 },
  { user: "Ana", amount: 5000 },
  { user: "Mark", amount: 20 }
]

for let t in transactions {
  if t.amount > 1000 {
    sldeploy("ALERT: Suspicious transaction by " + t.user)
  } else {
    sldeploy("Transaction OK: " + t.user)
  }
}

43. Chatbot Command Router

# chatbot.sl

while true {
  let msg = ask("Say something (exit to quit):")
  if msg == "exit" { break }

  if msg == "help" {
    sldeploy("Commands: help, time, joke")
  }
  if msg == "time" {
    sldeploy("Time feature coming soon")
  }
  if msg == "joke" {
    sldeploy("Why do programmers love dark mode?")
  }
}

44. Tournament Ranking System

# tournament.sl

let players = [
  { name: "A", score: 0 },
  { name: "B", score: 0 }
]

players[0].score += 3
players[1].score += 1

let winner = players[0]
for let p in players {
  if p.score > winner.score {
    winner = p
  }
}

sldeploy("Winner: " + winner.name)

45. System Health Monitor

# health_monitor.sl

let cpu = [40, 55, 80, 95]

for let usage in cpu {
  if usage > 90 {
    sldeploy("CRITICAL CPU usage: " + usage + "%")
  } else if usage > 70 {
    sldeploy("Warning CPU usage: " + usage + "%")
  } else {
    sldeploy("CPU OK: " + usage + "%")
  }
}

46. ATM Simulator

Description: Simulates a secure ATM allowing PIN verification, deposits, withdrawals, and balance checking. Includes attempt limits for security.
Keywords: ATM, PIN verification, transactions, balance, user input.
let pin = "1234"
let balance = 500
let attempts = 0

sldeploy("Welcome to SL Secure ATM")

# PIN verification
while attempts < 3 {
  let entered = ask("Enter your PIN:")
  if entered == pin { sldeploy("Access granted"); break }
  attempts += 1
  sldeploy("Incorrect PIN")
}

if attempts == 3 { sldeploy("Card blocked") }
else {
  while true {
    let cmd = ask("Choose: withdraw / deposit / balance / exit")
    
    if cmd == "exit" { break }

    if cmd == "balance" { sldeploy("Balance: $" + balance) }

    if cmd == "deposit" {
      let amt = num(ask("Amount to deposit:"))
      if amt > 0 { balance += amt; sldeploy("Deposited $" + amt) }
      else { sldeploy("Invalid amount") }
    }

    if cmd == "withdraw" {
      let amt = num(ask("Amount to withdraw:"))
      if amt > 0 and amt <= balance { balance -= amt; sldeploy("Withdrawn $" + amt) }
      else { sldeploy("Invalid or insufficient funds") }
    }
  }
}

sldeploy("Thank you for using SL ATM")
  

47. Budget & Expense Tracker

Description: Tracks expenses by category, computes totals, and alerts if budget is exceeded. Interactive input for real-time tracking.
Keywords: budgeting, expenses, categories, totals, alerts.
let expenses = []

sldeploy("Welcome to Budget Tracker")

while true {
  let cmd = ask("Choose: add / summary / exit")

  if cmd == "exit" { break }

  if cmd == "add" {
    let title = ask("Expense name:")
    let category = ask("Category (food, rent, bills, misc):")
    let amount = num(ask("Amount:"))
    expenses = expenses + [{ title: title, category: category, amount: amount }]
    sldeploy("Expense added")
  }

  if cmd == "summary" {
    let total = 0
    let categories = {}
    for let e in expenses {
      total += e.amount
      if not categories[e.category] { categories[e.category] = 0 }
      categories[e.category] += e.amount
    }

    sldeploy("Total expenses: $" + total)
    sldeploy("Category breakdown:")
    for let cat in keys(categories) { sldeploy(cat + " -> $" + categories[cat]) }

    if total > 1000 { sldeploy("Alert: You exceeded your budget!") }
  }
}
  

48. Bank Fraud Detection

Description: Checks transactions against a threshold and flags suspicious activity. Useful for monitoring large transfers.
Keywords: fraud detection, transactions, threshold, alerts.
let transactions = [
  { user: "Ana", amount: 50 },
  { user: "Ana", amount: 5000 },
  { user: "Mark", amount: 20 },
  { user: "Lena", amount: 15000 }
]

let threshold = 1000

sldeploy("Checking transactions for fraud...")

for let t in transactions {
  if t.amount > threshold {
    sldeploy("ALERT: Suspicious transaction by " + t.user + " -> $" + t.amount)
  } else {
    sldeploy("Transaction OK: " + t.user + " -> $" + t.amount)
  }
}
  

49. Loan Eligibility Checker

Description: Evaluates applicants' debt-to-income ratio to determine loan eligibility.
Keywords: loans, eligibility, debt-to-income, financial assessment.
let applicants = [
  { name: "John", income: 4000, debt: 1000 },
  { name: "Alice", income: 2000, debt: 2500 },
  { name: "Mark", income: 5000, debt: 1000 }
]

sldeploy("Loan Eligibility Report:")

for let a in applicants {
  let ratio = a.debt / a.income
  if ratio < 0.3 {
    sldeploy(a.name + " is eligible for loan")
  } else {
    sldeploy(a.name + " is NOT eligible for loan")
  }
}
  

50. Savings Goal Tracker

Description: Tracks progress toward multiple savings goals and indicates when a goal is reached.
Keywords: savings, goals, progress tracking, personal finance.
let goals = [
  { name: "Vacation", target: 2000, saved: 500 },
  { name: "Laptop", target: 1500, saved: 1500 },
  { name: "Emergency Fund", target: 5000, saved: 3000 }
]

sldeploy("Savings Goals Status:")

for let g in goals {
  let remaining = g.target - g.saved
  if remaining <= 0 {
    sldeploy(g.name + " -> Goal reached!")
  } else {
    sldeploy(g.name + " -> $" + remaining + " remaining")
  }
}
  

51. Investment Portfolio Analyzer

Description: Calculates total portfolio value, showing each stock’s individual value and overall sum.
Keywords: investments, stocks, portfolio, value calculation, finance analysis.
let portfolio = [
  { stock: "AAPL", qty: 10, price: 150 },
  { stock: "TSLA", qty: 5, price: 700 },
  { stock: "AMZN", qty: 2, price: 3300 }
]

sldeploy("Portfolio Summary:")

let total = 0
for let p in portfolio {
  let value = p.qty * p.price
  sldeploy(p.stock + " -> " + p.qty + " shares x $" + p.price + " = $" + value)
  total += value
}

sldeploy("Total portfolio value: $" + total)
  

52. Employee Management System

# employee_management.sl
let employees = []

sldeploy("Employee Management System")

while true {
  let cmd = ask("Choose: add / list / salary / exit")

  if cmd == "exit" { break }

  if cmd == "add" {
    let name = ask("Employee name:")
    let role = ask("Role:")
    let salary = num(ask("Salary:"))

    employees = employees + [{ name: name, role: role, salary: salary }]
    sldeploy("Employee added successfully")
  }

  if cmd == "list" {
    sldeploy("Employees:")
    for let e in employees {
      sldeploy(e.name + " | " + e.role + " | $" + e.salary)
    }
  }

  if cmd == "salary" {
    let total = 0
    for let e in employees { total += e.salary }
    sldeploy("Total payroll: $" + total)
  }
}

sldeploy("Employee Management System closed")

53. Inventory & Stock Management System

# inventory_system.sl
let inventory = []

sldeploy("Inventory & Stock Management System")

while true {
  let cmd = ask("Command: add / sell / list / exit")

  if cmd == "exit" { break }

  if cmd == "add" {
    let name = ask("Item name:")
    let qty = num(ask("Quantity:"))
    inventory = inventory + [{ name: name, qty: qty }]
    sldeploy("Item added to inventory")
  }

  if cmd == "sell" {
    let name = ask("Item name to sell:")
    let qty = num(ask("Quantity to sell:"))

    let found = false
    for let item in inventory {
      if item.name == name and item.qty >= qty {
        item.qty -= qty
        sldeploy("Sold " + qty + " of " + name)
        found = true
      }
    }

    if not found { sldeploy("Item not found or insufficient quantity") }
  }

  if cmd == "list" {
    sldeploy("Inventory:")
    for let i in inventory { sldeploy(i.name + " -> " + i.qty) }
  }
}

sldeploy("Inventory Management closed")

54. Project Task Management System (Mini Jira/Trello)

# project_manager.sl
let tasks = []

sldeploy("Project Task Management System")

while true {
  let cmd = ask("Choose: add / move / list / exit")

  if cmd == "exit" { break }

  if cmd == "add" {
    let title = ask("Task title:")
    tasks = tasks + [{ title: title, status: "todo" }]
    sldeploy("Task added to 'todo'")
  }

  if cmd == "move" {
    let title = ask("Task title to move:")
    let newStatus = ask("New status (todo / doing / done):")

    let found = false
    for let t in tasks {
      if t.title == title {
        t.status = newStatus
        sldeploy("Task '" + title + "' moved to " + newStatus)
        found = true
      }
    }

    if not found { sldeploy("Task not found") }
  }

  if cmd == "list" {
    sldeploy("Tasks:")
    for let t in tasks { sldeploy(t.title + " [" + t.status + "]") }
  }
}

sldeploy("Project Management System closed")