Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/you-win/advanced-expression-gd

More powerful Expressions for Godot
https://github.com/you-win/advanced-expression-gd

godot

Last synced: 3 days ago
JSON representation

More powerful Expressions for Godot

Awesome Lists containing this project

README

        

# Advanced Expression GD

[![Chat on Discord](https://img.shields.io/discord/853476898071117865?label=chat&logo=discord)](https://discord.gg/6mcdWWBkrr)
[![package](https://img.shields.io/badge/package-1.0.0-blue)](https://www.npmjs.com/package/@sometimes_youwin/advanced-expression)

Functions like Godot's built-in `Expression` class with the flexability of an actual script.

See the `tests/` directory for more examples.

## Example
```GDScript
var ae = preload("res://addons/advanced-expression/advanced_expression.gd")

# Add variables
# Currently, variables must be preinitialized with a value since,
# in the author's opinion, variables should avoid being null when possible
ae.add_variable("counter").add(0)

# Add function with a parameter
ae.add_function("increment") \
.add_param("input: int") \
.add("return input + 1")

# Add runner code that will be run on execute
# Follows the same semantics as regular functions
ae.add() \
.add_param("starting_value") \
.add("counter = starting_value") \
.add("for i in 5:") \
.tab() \
.add("counter = increment(counter)") \
.add("return counter")

# Everything must be compiled before executing
if ae.compile() != OK:
push_error("Failed to compile")

# Parameters must be passed as an array
# These are passed to the runner function
assert(ae.execute([1]) == 6)
```