### Wollok Game - Basic Setup and Configuration Source: https://context7.com/uqbar-project/wollok-language/llms.txt Configure game properties like title, dimensions, cell size, and ground image. Define and add visual objects and characters to the game. ```wollok // Game board configuration program myGame { game.title("My First Game") game.width(10) game.height(10) game.cellSize(50) game.ground("grass.png") // Create a visual object object player { var property position = game.at(5, 5) method image() = "player.png" } // Add objects to the game game.addVisual(player) // Add character with arrow key movement game.addVisualCharacter(player) // Start the game game.start() } // Position operations const pos = game.at(3, 4) pos.x() // => 3 pos.y() // => 4 pos.up(1) // => Position(3, 5) pos.down(1) // => Position(3, 3) pos.left(1) // => Position(2, 4) pos.right(1) // => Position(4, 4) pos.distance(game.origin()) // => 5.0 game.origin() // => Position(0, 0) game.center() // => Position at board center ``` -------------------------------- ### Inspect Object Structure with ObjectMirror Source: https://context7.com/uqbar-project/wollok-language/llms.txt The ObjectMirror class allows runtime inspection of object properties and values. Use instanceVariables() to get all variables and instanceVariableFor() to access specific ones. ```wollok class Person { const property name = "John" var property age = 30 } const person = new Person() const mirror = new ObjectMirror(target = person) // Get all instance variables const variables = mirror.instanceVariables() // => List of InstanceVariableMirror objects // Access specific variable const nameMirror = mirror.instanceVariableFor("name") nameMirror.name() // => "name" nameMirror.value() // => "John" nameMirror.valueToString() // => "John" nameMirror.toString() // => "name=John" // Resolve variable by name mirror.resolve("age") // => 30 ``` -------------------------------- ### Create and Use Wollok Dictionaries Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates creating a Dictionary, adding key-value pairs, and retrieving values. Handles missing keys using getOrElse and basicGet. ```wollok const phones = new Dictionary() phones.put("Alice", "555-1234") phones.put("Bob", "555-5678") phones.get("Alice") // => "555-1234" phones.get("Charlie") // => throws ElementNotFoundException phones.getOrElse("Charlie", { "N/A" }) // => "N/A" phones.basicGet("Charlie") // => null (no exception) ``` -------------------------------- ### Wollok Object Constructor and Initialization Source: https://github.com/uqbar-project/wollok-language/wiki/[DEPRECADO]-Unificación-de-implementaciones-de-Wollok Demonstrates the constructor and initialize method in Wollok objects. The current implementation checks for an initialize method, with a future plan to simplify initialization. ```wollok constructor() { self.initialize() } ``` ```wollok method initialize() { } ``` ```wollok initialize { const energia = 100 } ``` -------------------------------- ### Create and Manipulate Dates in Wollok Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates creating dates using calendar methods or specific day, month, and year. Shows how to access date components, check day types, and perform immutable date arithmetic. ```wollok // Creating dates const today = calendar.today() const birthday = new Date(day = 15, month = 3, year = 1990) const tomorrow = calendar.tomorrow() const yesterday = calendar.yesterday() ``` ```wollok // Date components birthday.day() // => 15 birthday.month() // => 3 birthday.year() // => 1990 ``` ```wollok // Day of week birthday.dayOfWeek() // => "thursday" (or appropriate day) birthday.internalDayOfWeek() // => 4 (1=Monday, 7=Sunday) birthday.isWorkDay() // => true (Monday-Friday) birthday.isWeekendDay() // => false ``` ```wollok // Date arithmetic (returns new Date, immutable) birthday.plusDays(10) // => March 25, 1990 birthday.plusMonths(2) // => May 15, 1990 birthday.plusYears(5) // => March 15, 1995 birthday.minusDays(5) // => March 10, 1990 ``` ```wollok // Date differences const date1 = new Date(day = 1, month = 1, year = 2024) const date2 = new Date(day = 10, month = 1, year = 2024) date2 - date1 // => 9 (days difference) ``` ```wollok // Comparisons date1 < date2 // => true date1 <= date2 // => true date1.between(new Date(day = 1, month = 1, year = 2023), new Date(day = 31, month = 12, year = 2024)) // => true ``` ```wollok // Year properties new Date(day = 1, month = 1, year = 2024).isLeapYear() // => true ``` -------------------------------- ### Wollok Closure Syntax and Usage Source: https://context7.com/uqbar-project/wollok-language/llms.txt Illustrates creating and applying closures with single, multiple, or no parameters. Shows how closures capture scope and can be used with collection methods and higher-order functions. ```wollok // Basic closure syntax const addOne = { n => n + 1 } addOne.apply(5) // => 6 ``` ```wollok // Multi-parameter closures const add = { a, b => a + b } add.apply(3, 4) // => 7 ``` ```wollok // No-parameter closures const sayHello = { "Hello, World!" } sayHello.apply() // => "Hello, World!" ``` ```wollok // Using closures with collections const numbers = [1, 2, 3, 4, 5] // Short syntax (braces only) numbers.filter { n => n > 2 } // => [3, 4, 5] numbers.map { n => n * 2 } // => [2, 4, 6, 8, 10] numbers.forEach { n => console.println(n) } ``` ```wollok // Closures capturing scope var total = 0 [1, 2, 3].forEach { n => total += n } total // => 6 ``` ```wollok // Higher-order functions method applyTwice(closure, value) { return closure.apply(closure.apply(value)) } applyTwice({ x => x * 2 }, 3) // => 12 ``` -------------------------------- ### Play Audio in Wollok Game Source: https://context7.com/uqbar-project/wollok-language/llms.txt Use game.sound() to create audio objects and control playback, volume, and looping. Play sounds on key presses using keyboard events. ```wollok program gameWithSound { // Create sound object const backgroundMusic = game.sound("music.mp3") const jumpSound = game.sound("jump.wav") // Basic playback backgroundMusic.play() // Volume control (0 to 1) backgroundMusic.volume(0.5) backgroundMusic.volume() // => 0.5 // Looping backgroundMusic.shouldLoop(true) backgroundMusic.shouldLoop() // => true // Playback state backgroundMusic.played() // => true (has been played) backgroundMusic.paused() // => false // Pause and resume backgroundMusic.pause() backgroundMusic.resume() // Stop completely backgroundMusic.stop() // Play sound on key press keyboard.space().onPressDo { jumpSound.play() } game.start() } ``` -------------------------------- ### Wollok Set Operations - Creation and Basic Usage Source: https://context7.com/uqbar-project/wollok-language/llms.txt Introduces set creation using '#{}' syntax and basic operations like size, contains, and retrieving an arbitrary element. Sets automatically handle duplicate removal. ```wollok // Set creation and basic operations const fruits = #{"apple", "banana", "orange"} fruits.size() // => 3 fruits.contains("apple") // => true fruits.anyOne() // => "apple" (or any element) // Adding duplicates has no effect const numbers = #{} numbers.add(3) // numbers = #{3} numbers.add(3) // numbers = #{3} (no change) numbers.add(5) // numbers = #{3, 5} ``` -------------------------------- ### Wollok String Split and Words Source: https://context7.com/uqbar-project/wollok-language/llms.txt Shows how to split a string into a list of substrings based on a delimiter and how to extract words from a string. ```wollok // Split and words "a,b,c".split(",") // => ["a", "b", "c"] "hello world".words() // => ["hello", "world"] "hello world".split(" ") // => ["hello", "world"] ``` -------------------------------- ### Console Input and Output Operations Source: https://context7.com/uqbar-project/wollok-language/llms.txt Use the console object for standard input and output. println() for outputting text or data, readLine() for string input, and readInt() for integer input. ```wollok // Output console.println("Hello, World!") console.println(42) console.println([1, 2, 3]) // Input const name = console.readLine() // reads a line of text const number = console.readInt() // reads an integer // Newline character (platform-specific) console.newline() // => "\n" on Unix, "\r\n" on Windows // Example interactive program program greeter { console.println("What is your name?") const name = console.readLine() console.println("Hello, " + name + "!") console.println("How old are you?") const age = console.readInt() console.println("You will be " + (age + 1) + " next year!") } ``` -------------------------------- ### Wollok String Case Transformations Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates converting strings to uppercase, lowercase, and capitalizing the first letter of each word. ```wollok // Case transformations "Hello".toUpperCase() // => "HELLO" "Hello".toLowerCase() // => "hello" "hello world".capitalize() // => "Hello World" ``` -------------------------------- ### Wollok Ranges and Iteration Source: https://context7.com/uqbar-project/wollok-language/llms.txt Illustrates creating number ranges, converting them to lists, calculating their sum, filtering elements, and iterating a specific number of times. ```wollok // Ranges and iteration (1..5).asList() // => [1, 2, 3, 4, 5] (1..5).sum() // => 15 (1..10).filter { n => n.even() } // => [2, 4, 6, 8, 10] 3.times { i => console.println(i) } // prints 1, 2, 3 0.randomUpTo(100) // => random number between 0 and 100 ``` -------------------------------- ### Wollok Key-Value Pair Creation Source: https://context7.com/uqbar-project/wollok-language/llms.txt Illustrates creating key-value pairs using the '->' operator, useful for simple associative data structures. Access values using the 'value()' method. ```wollok // Key-value pair creation with -> operator const pair = "name" -> "Wollok" pair.key() // => "name" pair.value() // => "Wollok" ``` -------------------------------- ### Wollok List Operations - Mutation and Sublists Source: https://context7.com/uqbar-project/wollok-language/llms.txt Shows how to modify lists in-place using methods like add, remove, and addAll, and how to extract sublists or reverse the list. Be aware of side effects when using mutation methods. ```wollok // List mutations (side effects) const items = [1, 2, 3] items.add(4) // items = [1, 2, 3, 4] items.remove(2) // items = [1, 3, 4] items.addAll([5, 6]) // items = [1, 3, 4, 5, 6] items.clear() // items = [] // Sublists and transformations [1, 2, 3, 4, 5].take(3) // => [1, 2, 3] [1, 2, 3, 4, 5].drop(2) // => [3, 4, 5] [1, 2, 3, 4, 5].subList(1, 3) // => [2, 3, 4] [1, 2, 3].reverse() // => [3, 2, 1] ``` -------------------------------- ### Wollok Number Properties and Functions Source: https://context7.com/uqbar-project/wollok-language/llms.txt Explains how to check number properties like even/odd, primality, absolute value, and inversion, along with mathematical functions like square root and GCD. ```wollok // Number properties 7.even() // => false 8.even() // => true 7.odd() // => true 7.isPrime() // => true (-5).abs() // => 5 (-3).invert() // => 3 // Math functions 9.squareRoot() // => 3 4.square() // => 16 8.gcd(12) // => 4 (greatest common divisor) 3.lcm(4) // => 12 (least common multiple) ``` -------------------------------- ### Inspect Wollok Dictionary Properties Source: https://context7.com/uqbar-project/wollok-language/llms.txt Shows how to check the size, emptiness, and contents of a Dictionary using methods like size(), isEmpty(), containsKey(), keys(), and values(). ```wollok // Dictionary inspection phones.size() // => 2 phones.isEmpty() // => false phones.containsKey("Alice") // => true phones.containsValue("555-1234") // => true phones.keys() // => ["Alice", "Bob"] phones.values() // => ["555-1234", "555-5678"] ``` -------------------------------- ### Wollok Range Operations Source: https://context7.com/uqbar-project/wollok-language/llms.txt Covers creating integer ranges with default or custom steps. Demonstrates accessing range properties, iterating, and using collection-like operations such as filter, map, and sum. ```wollok // Creating ranges const range = 1..10 // 1 to 10 inclusive const custom = new Range(start = 1, end = 10, step = 2) ``` ```wollok // Range properties range.start() // => 1 range.end() // => 10 range.size() // => 10 ``` ```wollok // Iteration (1..5).forEach { n => console.println(n) } // prints 1, 2, 3, 4, 5 ``` ```wollok // Collection-like operations (1..10).filter { n => n.even() } // => [2, 4, 6, 8, 10] (1..5).map { n => n * n } // => [1, 4, 9, 16, 25] (1..10).any { n => n > 5 } // => true (1..10).all { n => n > 0 } // => true (1..5).sum() // => 15 (1..5).min() // => 1 (1..5).max() // => 5 ``` ```wollok // Ranges with step new Range(start = 0, end = 10, step = 2).asList() // => [0, 2, 4, 6, 8, 10] new Range(start = 10, end = 1, step = -2).asList() // => [10, 8, 6, 4, 2] ``` ```wollok // Random element from range (1..100).anyOne() // => random number between 1 and 100 (1..10).contains(5) // => true ``` -------------------------------- ### Wollok Number Comparisons and Limits Source: https://context7.com/uqbar-project/wollok-language/llms.txt Shows how to find the maximum or minimum of two numbers, check if a number is within a range, and limit a number to a specific range. ```wollok // Comparisons and limits 5.max(8) // => 8 5.min(3) // => 3 7.between(5, 10) // => true 4.limitBetween(6, 10) // => 6 (nearest value in range) ``` -------------------------------- ### Wollok String Searching Source: https://context7.com/uqbar-project/wollok-language/llms.txt Shows how to check for the presence of substrings, and find the index of the first or last occurrence of a character or substring. ```wollok // String searching "hello".contains("ell") // => true "hello".startsWith("he") // => true "hello".endsWith("lo") // => true "hello".indexOf("l") // => 2 "hello".lastIndexOf("l") // => 3 ``` -------------------------------- ### Basic Arithmetic in Wollok Source: https://context7.com/uqbar-project/wollok-language/llms.txt Covers fundamental arithmetic operations including addition, subtraction, multiplication, division, integer division, remainder, and exponentiation. ```wollok // Basic arithmetic 5 + 3 // => 8 10 - 4 // => 6 6 * 7 // => 42 15 / 4 // => 3.75 15.div(4) // => 3 (integer division) 15 % 4 // => 3 (remainder) 2 ** 10 // => 1024 (power) ``` -------------------------------- ### Wollok List Operations - Finding and Sorting Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates methods for finding elements within a list, including default values and fallback logic, as well as sorting lists based on custom comparators. Useful for data retrieval and ordering. ```wollok // Finding elements numbers.find { n => n > 20 } // => 22 (throws if not found) numbers.findOrDefault({ n => n > 100 }, 0) // => 0 numbers.findOrElse({ n => n > 100 }, { 99 }) // => 99 // Sorting (returns new list, no side effect) numbers.sortedBy { a, b => a < b } // => [2, 5, 8, 10, 22] numbers.sortedBy { a, b => a > b } // => [22, 10, 8, 5, 2] ``` -------------------------------- ### Wollok Class Definitions and Inheritance Source: https://context7.com/uqbar-project/wollok-language/llms.txt Define classes with properties and methods. Use 'inherits' for inheritance and 'mixed with' for mixins to create reusable behavior. Named objects act as singletons. ```wollok // Basic class with properties class Animal { const property name var property energy = 100 method eat(food) { energy += food.calories() } method makeSound() { // Abstract - subclasses should override } } // Inheritance class Dog inherits Animal { override method makeSound() = "Woof!" method fetch() { energy -= 20 return "Ball retrieved!" } } // Mixins for shared behavior mixin Flying { method fly(distance) { self.energy(self.energy() - distance * 2) } } class Bird inherits Animal mixed with Flying { override method makeSound() = "Tweet!" } // Named objects (singletons) object pepita inherits Bird { override method makeSound() = "Pio pio!" } // Using classes const dog = new Dog(name = "Rex") dog.eat(object { method calories() = 50 }) dog.energy() // => 150 dog.makeSound() // => "Woof!" pepita.fly(10) pepita.makeSound() // => "Pio pio!" ``` -------------------------------- ### Wollok String Comparisons Source: https://context7.com/uqbar-project/wollok-language/llms.txt Covers lexicographical string comparisons and case-insensitive equality checks. ```wollok // Comparisons "abc" < "def" // => true "abc" == "abc" // => true "ABC".equalsIgnoreCase("abc") // => true ``` -------------------------------- ### Wollok Exception Handling Source: https://context7.com/uqbar-project/wollok-language/llms.txt Shows basic try-catch blocks for handling errors and catching specific exception types. Includes defining custom exceptions and accessing exception properties like message and stack trace. ```wollok // Basic try-catch try { const result = 10 / 0 } catch e { console.println("Error: " + e.message()) } ``` ```wollok // Catching specific exception types try { [].first() } catch e: ElementNotFoundException { console.println("Element not found!") } catch e: Exception { console.println("Other error: " + e.message()) } ``` ```wollok // Custom exceptions class InsufficientFundsException inherits DomainException {} ``` ```wollok object account { var balance = 100 method withdraw(amount) { if (amount > balance) { throw new InsufficientFundsException( message = "Cannot withdraw " + amount + ", balance is " + balance, source = self ) } balance -= amount } } ``` ```wollok // Exception properties try { account.withdraw(500) } catch e: InsufficientFundsException { e.message() // => "Cannot withdraw 500, balance is 100" e.source() // => account object e.printStackTrace() // prints full stack trace e.getStackTraceAsString() // => stack trace as string } ``` -------------------------------- ### Iterate Over Wollok Dictionary Source: https://context7.com/uqbar-project/wollok-language/llms.txt Illustrates iterating through a Dictionary using the forEach method to access each key-value pair. ```wollok // Iteration phones.forEach { key, value => console.println(key + ": " + value) } ``` -------------------------------- ### Rounding Operations in Wollok Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates various rounding methods for numbers, including rounding up, down, to the nearest integer, and truncating to a specified number of decimal places. ```wollok // Rounding operations 3.7.roundUp() // => 4 3.7.roundDown() // => 3 3.5.round() // => 4 3.14159.truncate(2) // => 3.14 1.2345.roundUp(2) // => 1.24 ``` -------------------------------- ### Wollok Game - Keyboard Input Handling Source: https://context7.com/uqbar-project/wollok-language/llms.txt Implement keyboard controls for game characters by binding actions to specific keys using closures. Supports arrow keys, letter keys, special keys, and any key. ```wollok program gameWithKeyboard { object character { var property position = game.at(5, 5) method image() = "hero.png" method moveUp() { position = position.up(1) } method moveDown() { position = position.down(1) } method moveLeft() { position = position.left(1) } method moveRight() { position = position.right(1) } } game.addVisual(character) // Arrow key bindings keyboard.up().onPressDo { character.moveUp() } keyboard.down().onPressDo { character.moveDown() } keyboard.left().onPressDo { character.moveLeft() } keyboard.right().onPressDo { character.moveRight() } // Letter keys keyboard.w().onPressDo { character.moveUp() } keyboard.a().onPressDo { character.moveLeft() } keyboard.s().onPressDo { character.moveDown() } keyboard.d().onPressDo { character.moveRight() } // Special keys keyboard.space().onPressDo { character.jump() } keyboard.enter().onPressDo { game.say(character, "Hello!") } keyboard.num1().onPressDo { character.useItem(1) } // Any key keyboard.any().onPressDo { console.println("A key was pressed") } // Clean up key binding keyboard.space().clean() game.start() } ``` -------------------------------- ### Wollok Set Operations - Collection Compatibility and Conversion Source: https://context7.com/uqbar-project/wollok-language/llms.txt Highlights that common collection methods like filter and map also work on sets, noting that map may return a list. Shows how to convert between lists and sets. ```wollok // All collection methods work on sets too #{1, 2, 3, 4}.filter { n => n.even() } // => #{2, 4} #{1, 2, 3}.map { n => n * 2 } // => [2, 4, 6] (returns list) // Converting between collections [1, 2, 2, 3, 3, 3].asSet() // => #{1, 2, 3} #{1, 2, 3}.asList() // => [1, 2, 3] ``` -------------------------------- ### Wollok String Manipulation Source: https://context7.com/uqbar-project/wollok-language/llms.txt Covers trimming whitespace, reversing strings, and concatenating strings using both the concat method and the '+' operator. ```wollok // String manipulation " hello ".trim() // => "hello" "hello".reverse() // => "olleh" "hello".concat(" world") // => "hello world" "hello" + " world" // => "hello world" ``` -------------------------------- ### Basic String Operations in Wollok Source: https://context7.com/uqbar-project/wollok-language/llms.txt Covers fundamental string properties like length and emptiness, and accessing characters or substrings. ```wollok // Basic operations "hello".length() // => 5 "hello".size() // => 5 "hello".isEmpty() // => false "".isEmpty() // => true // Character access and substrings "hello".charAt(1) // => "e" "hello world".substring(0, 5) // => "hello" "hello world".substring(6) // => "world" ``` -------------------------------- ### Wollok String Take and Drop Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates taking or dropping characters from the beginning or end of a string. ```wollok // Take and drop "clearly".take(2) // => "cl" "clearly".drop(2) // => "early" "hello".takeLeft(3) // => "hel" "hello".takeRight(3) // => "llo" ``` -------------------------------- ### Wollok Object Class - Equality and Error Handling Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates overriding the equality operator (==) for custom object comparison and handling domain exceptions with the 'error' method. Use for defining value equality for custom types and implementing custom error conditions. ```wollok // Equality comparison (==) - can be overridden class Person { const property name const property age override method ==(other) { return other.name() == self.name() && other.age() == self.age() } } const person1 = new Person(name = "John", age = 30) const person2 = new Person(name = "John", age = 30) person1 == person2 // => true (value equality) person1 === person2 // => false (identity - different objects) person1 !== person2 // => true // Error handling with custom domain exceptions object bankAccount { var balance = 1000 method withdraw(amount) { if (amount > balance) { self.error("Insufficient funds") // Throws DomainException } balance -= amount } } ``` -------------------------------- ### Wollok List Operations - Basic and Functional Source: https://context7.com/uqbar-project/wollok-language/llms.txt Covers fundamental list operations like size, access, and emptiness checks, alongside functional programming methods such as map, filter, and aggregation. Suitable for data manipulation and transformation. ```wollok // Basic list operations const numbers = [22, 2, 10, 5, 8] numbers.size() // => 5 numbers.isEmpty() // => false numbers.first() // => 22 numbers.last() // => 8 numbers.get(2) // => 10 (0-indexed) // Functional operations numbers.map { n => n * 2 } // => [44, 4, 20, 10, 16] numbers.filter { n => n > 5 } // => [22, 10, 8] numbers.any { n => n.even() } // => true numbers.all { n => n > 0 } // => true numbers.count { n => n > 5 } // => 3 numbers.sum() // => 47 numbers.average() // => 9.4 numbers.min() // => 2 numbers.max() // => 22 ``` -------------------------------- ### Wollok List Operations - Fold/Reduce Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates the fold (or reduce) operation for aggregating list elements into a single value. This is a powerful pattern for summarizing data. ```wollok // Fold/reduce pattern [1, 2, 3, 4].fold(0, { acum, n => acum + n }) // => 10 ``` -------------------------------- ### Wollok Set Operations - Mathematical Set Operations Source: https://context7.com/uqbar-project/wollok-language/llms.txt Explains how to perform standard mathematical set operations like union, intersection, and difference on Wollok sets. These are essential for set theory applications. ```wollok // Set-specific operations const setA = #{1, 2, 3, 4} const setB = #{3, 4, 5, 6} setA.union(setB) // => #{1, 2, 3, 4, 5, 6} setA.intersection(setB) // => #{3, 4} setA.difference(setB) // => #{1, 2} ``` -------------------------------- ### Wollok Game - Collisions and Timed Events Source: https://context7.com/uqbar-project/wollok-language/llms.txt Manage game logic by detecting collisions between objects and scheduling timed events. Supports continuous and one-time collision detection, as well as tick-based and scheduled events. ```wollok program gameWithCollisions { object player { var property position = game.at(5, 5) var property health = 100 method image() = "player.png" } object enemy { var property position = game.at(2, 2) method image() = "enemy.png" } object coin { var property position = game.at(7, 3) method image() = "coin.png" } game.addVisual(player) game.addVisual(enemy) game.addVisual(coin) // Continuous collision detection (triggers every frame while colliding) game.whenCollideDo(player, { other => if (other == enemy) { player.health(player.health() - 10) } }) // One-time collision detection (triggers once per collision) game.onCollideDo(player, { other => if (other == coin) { game.removeVisual(coin) game.say(player, "Got the coin!") } }) // Get colliders at runtime game.colliders(player) // => list of objects at same position game.uniqueCollider(player) // => single collider (throws if not exactly one) // Timed events game.onTick(1000, "moveEnemy", { enemy.position(enemy.position().right(1)) }) // One-time scheduled event game.schedule(5000, { game.say(player, "5 seconds passed!") }) // Remove tick event game.removeTickEvent("moveEnemy") game.start() } ``` -------------------------------- ### Wollok Assertions for Unit Testing Source: https://context7.com/uqbar-project/wollok-language/llms.txt Use the assert object for various unit testing scenarios, including equality, boolean conditions, exceptions, and custom failure messages. ```wollok describe "Calculator tests" { test "basic addition" { assert.equals(4, 2 + 2) } test "boolean assertions" { assert.that(5 > 3) assert.notThat(3 > 5) } test "not equals" { assert.notEquals(5, 10) } test "exception testing" { assert.throwsException { => [].first() } } test "exception with specific message" { assert.throwsExceptionWithMessage( "collection is empty", { => [].max() } ) } test "exception with specific type" { assert.throwsExceptionWithType( new ElementNotFoundException(), { => [].first() } ) } test "no exception thrown" { assert.doesNotThrowException { => 1 + 1 } } test "custom failure message" { if (someCondition) { assert.fail("This should not happen") } } } ``` -------------------------------- ### Wollok String Replace Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates replacing occurrences of a substring within a string with a new substring. ```wollok // Replace "hello world".replace("world", "wollok") // => "hello wollok" ``` -------------------------------- ### Modify Wollok Dictionary Source: https://context7.com/uqbar-project/wollok-language/llms.txt Demonstrates removing elements and clearing all contents from a Dictionary using remove() and clear(). ```wollok // Modifications phones.remove("Bob") phones.clear() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.