#What things am I missing?

13 messages · Page 1 of 1 (latest)

mortal pasture
#

I want to write a toy-level simulation in Bevy, but from scratch. So I do not use the DefaultPlugins. This is my code now:

use bevy::prelude::*;

fn main() {
    App::new()
    .add_systems(Startup, startup)
    .run();
}


#[derive(Component)]
struct HP(i32);

fn acid_rain(
    mut q:Query<&mut HP>
) {
    q.for_each_mut(|mut hp| {
        hp.0 -= 1;
    })
}


fn startup(
    mut commands:Commands
) {
    commands.spawn(HP(100));
}

The problem was - it terminated immediately. So is there anything am I missing?

proper quail
#

that's because you don't have anything to run the app's schedule, that's usually handled by WinitPlugin for GUI apps or ScheduleRunnerPlugin for headless apps

#

it includes the bare minimum for headless programs

rocky gale
#

You want MinimalPlugins

mortal pasture
#

@proper quail @rocky gale ty. I'll try it. BTW, what is a schedule? Since bevy updated the Schedule System several times, so I do not understand it now.

proper quail
mortal pasture
#

I had written a python version looked like:


def main_loop(delta_time):
  # delta_time is adaptive to both fixed-step and variable-step simulation.
  pass

how could I do for migrating it ?

proper quail
#

the Update schedule is equivalent to your main loop: .add_systems(Update, ...)

#

and to get delta_time you can add a Res<Time> input to a system like this:

fn delta_time_example(time: Res<Time>) {
   dbg!(time.delta_seconds());
}
mortal pasture
#

ty. u solved my problems. 🙂

mortal pasture
#

@proper quail How can I get a fixed-interval timer or else? If I want to run my system in fixed-step?

proper quail