Skip to content

Commit bb50146

Browse files
authored
Updates to fix multiplayer bug found in tutorial. (#23)
These changes match those found in the Docs side with PR clockworklabs/spacetime-docs#169
1 parent 724ac3b commit bb50146

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

demo/Blackholio/server-csharp/Lib.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,13 @@ public static void MoveAllPlayers(ReducerContext ctx, MoveAllPlayersTimer timer)
350350
//Handle player input
351351
foreach (var circle in ctx.Db.circle.Iter())
352352
{
353-
var circle_entity = ctx.Db.entity.entity_id.Find(circle.entity_id) ?? throw new Exception("Circle has no entity");
353+
var check_entity = ctx.Db.entity.entity_id.Find(circle.entity_id);
354+
if (check_entity == null)
355+
{
356+
// This can happen if the circle has been eaten by another circle.
357+
continue;
358+
}
359+
var circle_entity = check_entity.Value;
354360
var circle_radius = MassToRadius(circle_entity.mass);
355361
var direction = circle_directions[circle.entity_id];
356362
var new_pos = circle_entity.position + direction * MassToMaxMoveSpeed(circle_entity.mass);

demo/Blackholio/server-rust/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,12 @@ pub fn move_all_players(ctx: &ReducerContext, _timer: MoveAllPlayersTimer) -> Re
406406

407407
// Handle player input
408408
for circle in ctx.db.circle().iter() {
409-
let mut circle_entity = ctx.db.entity().entity_id().find(&circle.entity_id).unwrap();
409+
let circle_entity = ctx.db.entity().entity_id().find(&circle.entity_id);
410+
if !circle_entity.is_some() {
411+
// This can happen if a circle is eaten by another circle
412+
continue;
413+
}
414+
let mut circle_entity = circle_entity.unwrap();
410415
let circle_radius = mass_to_radius(circle_entity.mass);
411416
let direction = *circle_directions.get(&circle.entity_id).unwrap();
412417
let new_pos =

0 commit comments

Comments
 (0)