From 935cabea8b4570689532932a5c715e1ea9b11fc2 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Mon, 16 May 2022 23:39:30 -0300 Subject: Encapsule InitMaze in a do{}while loop so it is always valid (I hope) Fix a typo as well --- npc/functions/maze.txt | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'npc') diff --git a/npc/functions/maze.txt b/npc/functions/maze.txt index 23caede37..27c026c4f 100644 --- a/npc/functions/maze.txt +++ b/npc/functions/maze.txt @@ -51,26 +51,25 @@ function script CreateMaze { if (MAZE_ID == .@r) continue; MAZE_ID = .@r; - break; - } while (true); - .@MAZEMP$=sprintf("030-%02d", MAZE_ID); - MAZE_MAP$=sprintf("mz%02d@"+getcharid(0), MAZE_ID); + .@MAZEMP$=sprintf("030-%02d", MAZE_ID); + MAZE_MAP$=sprintf("mz%02d@"+getcharid(0), MAZE_ID); - // Maze is not yet started - if (.@scope == IOT_CHAR) { - MAZE_INST = instance_create("Maze "+MAZE_ID+" "+getcharid(0), getcharid(3), IOT_CHAR); - // Failed - if (MAZE_INST < 0) { - consolebug("Instance \"%s\" already exists! (Error %d)", "Maze "+MAZE_ID+" "+getcharid(0), MAZE_INST); - return 0; + // Maze is not yet started + if (.@scope == IOT_CHAR) { + MAZE_INST = instance_create("Maze "+MAZE_ID+" "+getcharid(0), getcharid(3), IOT_CHAR); + // Failed + if (MAZE_INST < 0) { + consolebug("Instance \"%s\" already exists! (Error %d)", "Maze "+MAZE_ID+" "+getcharid(0), MAZE_INST); + continue; // Get a new maze + } + // Attach map + instance_attachmap(.@MAZEMP$, MAZE_INST, false, MAZE_MAP$); + } else { + consolebug("Scope %d not yet supported by maze system", .@scope); + return 0; // Exit early } - // Attach map - instance_attachmap(.@MAZEMP$, .@inst, false, MAZE_MAP$); - } else { - consolebug("Scope %d not yet supported by maze system", .@scope); - return 0; - } + } while (MAZE_INST < 0); return MAZE_ID; } -- cgit v1.2.3-60-g2f50