bevy_mod_scripting 0.19.0

Multi language scripting in Bevy
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
let type = world.get_type_by_name.call("SimpleEnum");

// Struct Variant
let constructed = construct.call(type, #{ variant: "Struct", foo: 123 });

assert(constructed.variant_name.call() == "Struct", "Value was constructed incorrectly, expected constructed.variant to be Struct but got " + constructed.variant_name.call());
assert(constructed.foo == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed.foo);

// TupleStruct Variant
constructed = construct.call(type, #{ variant: "TupleStruct", "0": 123 });

assert(constructed.variant_name.call() == "TupleStruct", "Value was constructed incorrectly, expected constructed.variant to be TupleStruct but got " + constructed.variant_name.call());
assert(constructed[0] == 123, "Value was constructed incorrectly, expected constructed[0] to be 123 but got " + constructed[0]);

// Unit Variant
constructed = construct.call(type, #{ variant: "Unit" });

assert(constructed.variant_name.call() == "Unit", "Value was constructed incorrectly, expected constructed.variant to be Unit but got " + constructed.variant_name.call());