amethyst / amethyst/rustrogueliketutorial

RandomTable.roll() returning None fairly freqently.

Đang mở
#205 1 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
970
Fork
166
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

To see the problem in action, get to a random map from chapter 45 on-wards.
The message "WARNING: We don't know how to spawn [None]!" should show up a number of times in the log.

Currently, whenever you roll 0, or exactly the sum of a number of item weights, nothing is spawned.
For example, if the first few items are weighted at [1,3,2,3,1...], then roll() would return "None" if the rng hits 0,1,4,6,9 or 10.
I'm assuming this is unintended behavior, but you can see pretty clearly why this happens in the code:
```rust
while roll > 0 {
if roll < self.entries[index].weight {
return self.entries[index].name.clone();
}

roll -= self.entries[index].weight;
index += 1;
}
```
There are two easy fixes that I can see. Both effectively just looping more:
```rust
while roll >= 0 { ...
```
or
```rust
while index < self.entries.len() { ..
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.