//! Shows how anonymous functions / closures can be used as systems.12use bevy::{log::LogPlugin, prelude::*};34fn main() {5// create a simple closure.6let simple_closure = || {7// this is a closure that does nothing.8info!("Hello from a simple closure!");9};1011// create a closure, with an 'input' value.12let complex_closure = |mut value: String| {13move || {14info!("Hello from a complex closure! {}", value);1516// we can modify the value inside the closure. this will be saved between calls.17value = format!("{value} - updated");1819// you could also use an outside variable like presented in the inlined closures20// info!("outside_variable! {}", outside_variable);21}22};2324let outside_variable = "bar".to_string();2526App::new()27.add_plugins(LogPlugin::default())28// we can use a closure as a system29.add_systems(Update, simple_closure)30// or we can use a more complex closure, and pass an argument to initialize a Local variable.31.add_systems(Update, complex_closure("foo".into()))32// we can also inline a closure33.add_systems(Update, || {34info!("Hello from an inlined closure!");35})36// or use variables outside a closure37.add_systems(Update, move || {38info!(39"Hello from an inlined closure that captured the 'outside_variable'! {}",40outside_variable41);42// you can use outside_variable, or any other variables inside this closure.43// their states will be saved.44})45.run();46}474849