Author Topic: Mysterious issues with creating bricks  (Read 1684 times)

It's getting late and I'm tired now. But I have been tormented by this issue for a few hours now, and I still have gotten nowhere. I ran a trace, basically my bricks start deleting themselves once 177 of them are created. This can work perfectly fine up until then, and then suddenly the bricks stop spawning and I'm flooded with 'cannot find object' errors (Primarily occurring from the onAdd). A slightly separate issue is that when I call createDungeon("0 0"); %room ends up being 1 instead of "0 0", I can't fathom why.

If you can figure out what I've done wrong, I'm glad to hear it. I'm really tired, so you probably won't hear from me tonight unless you answer in the next 20 minutes lol.

function startDungeon(%clear)
{
   if(%clear)
      brickGroup.deleteall();
   
   deleteVariables("$dungeonMaster*"); //Clean up the array
   
   %clients = clientGroup.getCount(); //GET IN HERE
   for(%i=0;%i<%clients;%i++)
   {
      %client = clientGroup.getObject(%i);
      
      if(%client.minigame.isTheDungeonOfDoomyDoom && isObject(%client.player))
         %client.player.setTransform("0 0 1");
         
   }
   
   $dungeonMaster[0, 0] = 0 SPC 0;
   createDungeon("0 0");
}

function createDungeon(%room)
{
   %x = firstWord(%room);
   %y = getword(%room, 1);
   
   //Baseplate
   makeDungeonBrick("0 0 0.5", brick32x32fdata, 8, %room, 0);
   
   //Doors
   makeDungeonBrick("7.75 0 2", brick1x6x5data, 6, %room, 0, 2);
   makeDungeonBrick("0 7.75 2", brick1x6x5data, 6, %room, 1, 1);
   makeDungeonBrick("-7.75 0 2", brick1x6x5data, 6, %room, 0, 4);
   makeDungeonBrick("0 -7.75 2", brick1x6x5data, 6, %room, 1, 3);
   
   //Walls
   makeDungeonBrick("7.75 4.5 2", brick1x12x5data, 7, %room, 0);
   makeDungeonBrick("7.75 -4.5 2", brick1x12x5data, 7, %room, 0);
   makeDungeonBrick("-7.75 4.5 2", brick1x12x5data, 7, %room, 0);
   makeDungeonBrick("-7.75 -4.5 2", brick1x12x5data, 7, %room, 0);
   
   makeDungeonBrick("4.5 7.75 2", brick1x12x5data, 7, %room, 1);
   makeDungeonBrick("4.5 -7.75 2", brick1x12x5data, 7, %room, 1);
   makeDungeonBrick("-4.5 7.75 2", brick1x12x5data, 7, %room, 1);
   makeDungeonBrick("-4.5 -7.75 2", brick1x12x5data, 7, %room, 1);

   //Corners
   makeDungeonBrick("7.75 7.75 2", brick1x1x5data, 7, %room, 0);
   makeDungeonBrick("7.75 -7.75 2", brick1x1x5data, 7, %room, 0);
   makeDungeonBrick("-7.75 7.75 2", brick1x1x5data, 7, %room, 0);
   makeDungeonBrick("-7.75 -7.75 2", brick1x1x5data, 7, %room, 0);

}

function makeDungeonBrick(%position, %data, %color, %room, %rot, %door)
{
   %rot=eulerToMatrix("0 0 "@(%rot % 4)*90);
   
   %brick = new fxDTSBrick()
   {
      client = findClientByBL_ID(getNumKeyID());
      dataBlock = %data;
      position = vectorAdd(%position,vectorScale(%room,16));
      rotation = %rot;
      colorID = %color;
      scale = "1 1 1";
      angleID = 0;
      colorfxID = 0;
      shapefxID = 0;
      isPlanted = 1;
      stackBL_ID = getNumKeyID();
      dungeonRoom = %room;
   };
   %brick.plant();
   %brick.setTrusted(1);
   
   nameToID("brickGroup_"@getNumKeyID()).add(%brick);
   
   
   if(%door)
   {
      %brick.addEvent(1, 0, "onActivate", "self", "openDungeonDoor", %door);
   }
}

function fxDtsBrick::openDungeonDoor(%this, %direction)
{
   %room = %this.dungeonRoom;
   %x = firstword(%room);
   %y = getWord(%room, 1);
   
   
   switch(%direction)
   {
      case 1:
         %y++;
         
      case 2:
         %x++;
         
      case 3:
         %y--;
         
      case 4:
         %x--;
   }
   
   if($dungeonMaster[%x, %y] $= "")
   {
      echo("Created the" SPC %x SPC %y SPC "dungeon room");
      $dungeonMaster[%x, %y] = %x SPC %y;
      createDungeon(%x SPC %y);
   }
   
   else
      echo("Sorry, room taken :/" SPC %x SPC %y);
   
   %this.disappear(-1);
}

registerOutputEvent(fxDtsBrick, openDungeonDoor, "INT 0 4 0", 0);

You're clearing brickGroup
Code: [Select]
   if(%clear)
      brickGroup.deleteall();
   
But the bricks are in brickGroup29450
Code: [Select]
   nameToID("brickGroup_"@getNumKeyID()).add(%brick);
Can't find what would cause those issues though. How are you creating the 177 bricks? Calling createdungeon multiple times?

I have absolutely no idea what could be causing that, but try making the bricks be public. That should also allow it to work on dedicated.

Also, i recommend that you don't just generate rooms where the player is going into, but also the room adjacent to that room. When the bricks are planted, they will have that white flash, which would look very strange in a dark dungeon.

Oh, another thing i just thought of, i remember reading somewhere that when creating bricks, you should schedule the plant(), just a 0 delay should do it. You might wanna schedule other things that happen after it as well to avoid other errors.
« Last Edit: December 01, 2013, 06:53:34 AM by boodals 2 »

Thanks for the input, but none of this has changed the result.

Inspired by your code, i decided to attempt to write my own dungeon generator. I've managed to get a system (based on BVSS) which can load preset rooms into a given position rotated as desired. But i haven't found any issues to do with what your finding.

As an educated guess, I think your problem lies with the brickgroups, or owner client stuff. I recommend you create your own client to store the bricks on, then make each brick owned by that client. Heres the code that I'm using.

Code: [Select]
if(isObject(FakeAdminClient)) { //Fake admin client to do admin stuffs
FakeAdminClient.delete();
}

new AiConnection(FakeAdminClient) {
isAdmin = 1;
isSuperAdmin = 1;

brickGroup = 0;
bl_id = 666;
};

$BRPG::brickGroup = new SimGroup("BrickGroup_666") {
client = FakeAdminClient;
bl_id = 666;
name = "God";
};

FakeAdminClient.brickGroup = $BRPG::brickGroup;
mainBrickGroup.add($BRPG::brickGroup);
Then when creating a brick:
Code: [Select]
%brick = new fxDTSBrick() {
client = FakeAdminClient;
stackBL_ID = FakeAdminClient.bl_id;
//Other stuff like position
};

It's worth mentioning that echoing %brick immediately after creating it shows 0. It appears the issue lies in the actual creation of the brick object, not the script. My guess is that there's some check Badspot put in that will cause brick generation to fail under certain circumstances. When creating a new object fails, there should ideally be an error printed to the console, but such is obviously not the case.

Are you creating bricks too quickly? Temporarily set the BPS limit to something higher and then revert it once you're done.

Are you creating bricks too quickly? Temporarily set the BPS limit to something higher and then revert it once you're done.
Each room is generated well after the last. Like I said, the rooms generate perfectly fine until I get to seventh room. From there, either all the bricks won't load, or only the baseplate and maybe one or two other bricks will load. The rest just fail to create. This is only when it is operating via the openDungeonDoor events. I can open a door where the room doesn't load, and then just do createDungeon("coordinate"); and it loads perfectly fine. I've checked and double checked that the coordinate parameter is passed exactly the same in the event script as it is when I eval it.

events are your problem

replace %brick.addEvent~~~
with

%brick.dungeonDoor=%door;


put this in:

package clickyDungeon
{
   function Player::Activatestuff(%obj)
   {
      Parent::Activatestuff(%obj);
      %ray = containerRaycast(%obj.getEyePoint(),vectorAdd(%obj.getEyePoint(),vectorScale(%obj.getEyeVector(),10)),$Typemasks::fxBrickObjectType,%obj);
      if(isObject(%col=firstWord(%ray)))
      {
         if(%col.dungeonDoor)
            %col.openDungeonDoor(%col.dungeonDoor);
      }
   }
};
activatepackage(clickydungeon);


(Make it better than my junk)

« Last Edit: December 03, 2013, 12:35:51 AM by MARBLE MAN »

Thanks! But I wonder what is wrong with using events.