Hands-on Rust: Chapter 5 “Storing the Dungeon Map: no instructions to modify main() before first run

There are no instructions to modify main() prior to the first attempt to run the sample code. As a result, run just prints out the default “Hello World”)

(Also, there were no instructions to add bracket-lib to the Cargo.toml dependencies)

Thanks! I’ve added this to the issue tracker.

main.rs instructions

The Consume the Map API section - the very last part of Storing the Dungeon Map - contains the instructions you requested (sorry about the formatting, it didn’t copy over well):

With the Map module ready to go, all that remains is to use it. Open main.rs.
You need to add a Map to the State object, and initialize it State’s constructor.
The tick() function should call the map’s render() function.
BasicDungeonCrawler/dungeon_crawl_map/src/main.rs

struct State {
  map: Map,
}
impl State {
  fn new() -> Self {
    Self { map: Map::new() }
  }
}
impl GameState for State {
  fn tick(&mut self, ctx: &mut BTerm) {
    ctx.cls();
    self.map.render(ctx);
  }
}

Run the program now, and you’ll see an empty map:

Cargo.toml

I agree that this could be a little confusing. Early in the chapter (after the module graphic) the book asks you to use follow the same steps you used in Hello Bracket Terminal to display “Hello Bracket World”. I’ll include Cargo.toml instructions in the setup text. Page-count permitting, I may be able to flesh it out a bit more.

Thanks!

1 Like

It’s missing the part that says to change main() to:

fn main() -> BError {
    let context = BTermBuilder::simple80x50()
        .with_title("Dungeon Crawler")
        .build()?;

    main_loop(context, State::new())
}

I found it in the downloaded code (could have copied over from previous project as well), but I’m assuming you don’t want readers to have to track down stuff like this.

1 Like

Aha! Thank you! I’ll get that into the next beta build.

1 Like