This directory contains example scripts demonstrating FerrisScript's features and capabilities.
All .ferris files now include standardized TEST headers for headless test runner integration:
// TEST: test_name
// CATEGORY: unit|integration
// DESCRIPTION: Brief description
// EXPECT: success|error
// ASSERT: Expected output lines
Benefits:
- Automated test discovery and validation
- Consistent documentation structure
- Headless testing support
- CI/CD integration ready
See: docs/testing/TESTING_GUIDE.md for full testing patterns
NEW: Test files for Inspector integration with @export properties!
- Test File:
inspector_minimal.ferris- Simple working test with 7 properties - Guide:
INSPECTOR_MINIMAL_TEST_GUIDE.md- Step-by-step testing instructions - Status: ✅ Compiles successfully, ready for testing
- Test File:
inspector_test.ferris- Complete test suite with 20+ properties (in godot_test/scripts/) - Status:
⚠️ Parser issues - use minimal test instead - Full Guide:
INSPECTOR_TEST_GUIDE.md- Detailed testing instructions - Quick Ref:
INSPECTOR_QUICK_REF.md- Quick reference
Get Started: See Inspector Minimal Test Guide for testing instructions.
To verify an example compiles correctly and see error messages:
# Test any FerrisScript file
cargo run --example test_ferris -- examples/hello.ferris
# See what error messages look like
cargo run --example test_ferris -- examples/error_showcase.ferris
# Or run the test suite for all examples
cargo test --package ferrisscript_compiler test_compileTo actually execute examples, you need to run them in Godot with the FerrisScript GDExtension. See the "Running Examples in Godot" section below for setup instructions.
Demonstrates: Basic function declaration, string literals, print() built-in
The classic "Hello, World!" program showing the simplest valid FerrisScript program.
fn _ready() {
print("Hello from FerrisScript!");
}
See hello/README.md for more details and common mistakes.
Demonstrates: Function parameters, return types, type annotations, arithmetic
Shows how to define functions with parameters and return values.
fn add(x: i32, y: i32) -> i32 {
return x + y;
}
Demonstrates: If/else statements, boolean conditions, comparison operators
Shows how to use conditional statements to control program flow.
Demonstrates: While loops, mutable state, compound assignment
Shows how to use while loops for iteration and counter patterns.
Demonstrates: Godot lifecycle methods, Vector2, field access, _process()
A simple script that moves a Godot node horizontally. Shows how FerrisScript integrates with Godot's game loop.
See move/README.md for Godot setup instructions.
Demonstrates: Global mutable state, control flow, compound assignment, game logic
A bouncing ball simulation showing how to manage game state and respond to boundaries.
See bounce/README.md for more details.
Demonstrates: FerrisScript's helpful error messages with source context
An interactive example showing how FerrisScript provides helpful error messages. Uncomment different sections to see various error types with:
- Source context (±2 lines around the error)
- Visual pointer (^) showing exact error location
- Helpful hints explaining what's expected
How to Use:
-
See it compile successfully:
cargo run --example test_ferris -- examples/error_showcase.ferris
Output:
✓ Compilation successful! -
See error messages in action:
-
Open
error_showcase.ferris -
Uncomment any error section (e.g., lines 71-73 for "Type Mismatch Error")
-
Run the test again:
cargo run --example test_ferris -- examples/error_showcase.ferris
-
See the error with source context, pointer, and helpful hint!
-
-
Learn by reading: Browse through the commented examples to understand different error types without needing to trigger them.
These examples demonstrate planned features:
collections.ferris- Arrays and collections (v0.1.0+)match.ferris- Pattern matching (v0.1.0+)scene.ferris- Advanced Godot integrationreload.ferris- Hot reload capabilitiestype_error.ferris- Type system demonstration
FerrisScript provides helpful error messages with source context to help you fix issues quickly.
When you make a mistake, FerrisScript shows you exactly what went wrong:
Code with Error:
fn test() {
let x: i32 = true; // Type mismatch
}
Error Output:
Type mismatch in let binding 'x': expected i32, found bool at line 2, column 18
1 | fn test() {
2 | let x: i32 = true;
| ^ Value type bool cannot be coerced to i32
3 | }
What the error shows:
- Error Message: Clear description of what went wrong
- Location: Line 2, column 18
- Source Context: ±2 lines of code around the error
- Visual Pointer:
^pointing to the exact problem location - Helpful Hint: "Value type bool cannot be coerced to i32"
let x: i32 = "hello"; // Error: Can't assign string to i32
The error message will show:
- What type was expected (i32)
- What type was found (string)
- A hint about type coercion rules
let x = undefined_var; // Error: Variable not declared
The error message will show:
- Which variable is undefined
- Where you tried to use it
- A hint: "Variable must be declared before use"
if 5 { // Error: Condition must be bool
print("test");
}
The error message will show:
- That the condition must be a boolean
- What type was found (i32)
- A hint: "Condition must evaluate to a boolean value (true or false)"
print(42); // Error: Wrong argument type
The error message will show:
- Function name and argument number
- Expected type (string)
- Found type (i32)
- A hint about the correct argument type
-
Read the Full Error: Don't just look at the first line - the source context and hints are valuable!
-
Check the Pointer: The
^character points to exactly where the error occurred. -
Follow the Hints: Error hints explain what's expected and often suggest how to fix the issue.
-
Try error_showcase.ferris: Uncomment different error sections to learn about common mistakes.
-
Common Mistakes READMEs: Check example-specific READMEs (like
hello/README.md) for common errors in that context.
Each example can have its own directory with additional documentation:
examples/
hello.ferris - Standalone example
hello/ - Example with additional docs
README.md - Detailed documentation
common_mistakes.md - Common errors for this example
For complex examples or Godot-specific examples, check the subdirectory for setup instructions and troubleshooting.
When adding new examples:
- Keep It Simple: Each example should demonstrate one or two features clearly
- Add Comments: Explain what's happening in the code
- Include README: For complex examples, add a README.md in a subdirectory
- Test It: Ensure the example compiles and runs correctly
- Show Errors: Consider adding a "Common Mistakes" section
See EXAMPLE_UPDATE_OPPORTUNITIES.md in the docs/ folder for planned example improvements.
For Godot examples (move, bounce, etc.), you need to:
- Open the
godot_testproject in Godot - Copy the .ferris script to
godot_test/scripts/ - Attach the script to a node in the scene
- Run the scene in Godot
See individual example READMEs for specific setup instructions.
- EXAMPLE_UPDATE_OPPORTUNITIES.md - Planned example improvements
- EDGE_CASE_ERROR_HANDLING_PLAN.md - Error handling system details
- v0.1.0-ROADMAP.md - Upcoming features that will need examples
Last Updated: October 2025
FerrisScript Version: v0.0.2