bevy_scriptum/book/src/ruby/spawning_scripts.md
Jarosław Konik 53479f94b5
Some checks are pending
Book / test (push) Waiting to run
Deploy book / deploy (push) Waiting to run
Rust / build (push) Waiting to run
Ruby support (#19)
Add support for Ruby language
2025-05-27 19:19:52 +02:00

42 lines
1.1 KiB
Markdown

# Spawning scripts
To spawn a Ruby script you will need to get a handle to a script asset using
bevy's `AssetServer`.
```rust
# extern crate bevy;
# extern crate bevy_scriptum;
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::ruby::prelude::*;
fn my_spawner(mut commands: Commands, assets_server: Res<AssetServer>) {
commands.spawn(Script::<RubyScript>::new(
assets_server.load("my_script.rb"),
));
}
```
After they scripts have been evaled by bevy_scriptum, the entities that they've
been attached to will get the `Script::<RubyScript>` component stripped and instead
```RubyScriptData``` component will be attached.
So to query scipted entities you could do something like:
```rust
# extern crate bevy;
# extern crate bevy_scriptum;
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::ruby::prelude::*;
fn my_system(
mut scripted_entities: Query<(Entity, &mut RubyScriptData)>,
) {
for (entity, mut script_data) in &mut scripted_entities {
// do something with scripted entities
}
}
```