Page 1 of 1

ManiaScript Bug ? [solved]

Posted: 08 Sep 2011, 20:43
by SurferIX
Here's my code, I'll explain line by line:
- 1) remove everything, then find the Base Coord:

Code: Select all

  declare CBlockModel BMArenaSimpleBase;
  BMArenaSimpleBase <=> BlockModels["ArenaSimpleBase"];
  RemoveAllBlocksAndTerrain();
  declare CoordYBaseSol = GetBlockGroundHeight(
    BMArenaSimpleBase, 19, 19, ::CardinalDirections::East);
- 2) Put a block on <3, BaseGround, 0>

Code: Select all

  PlaceBlock(BlockModels["RoadRaceToArenaMirror"], <3, CoordYBaseSol, 0>, ::CardinalDirections::East);
- 3) Test where I've put the block: there should be something. Thus B should not be Null. Thus log(B == Null); should give at least once "False", but nope:

Code: Select all

  declare CGameCtnBlock B;
  B = GetBlock(<3, CoordYBaseSol-2, 0>);
  log(B == Null);
  B = GetBlock(<3, CoordYBaseSol-1, 0>);
  log(B == Null);
  B = GetBlock(<3, CoordYBaseSol, 0>);
  log(B == Null);
  B = GetBlock(<3, CoordYBaseSol+1, 0>);
  log(B == Null);
  B = GetBlock(<3, CoordYBaseSol+2, 0>);
  log(B == Null);
For the people who want to test and explain if it's a bug or if I'm wrong, here's the full code, just copy/paste it'll work:

Code: Select all

#RequireContext CGameCtnEditorPluginScriptHandler
#Include "MapUnits" as MapUnits
#Include "MathLib" as MathLib
Text CreateManialink()
{
  declare MLText =
  """
    <script><!--
      Void OnPlaceBlocks()
      {
        declare Boolean StartPlacing for Page;
        if(!StartPlacing) {
          StartPlacing = True;
        }
      }
      main ()
      {
        while(True) {
          yield;
          foreach(Event in PendingEvents) {
            if(Event.Type == CGameManialinkScriptEvent::Type::MouseClick) {
              if (Event.ControlId == "PlaceQuad") {
                OnPlaceBlocks();
              }
            }
          }
        }
      }
    --></script>
    <frame>
      <quad id="PluginTitleQuad" posn="-138 82 1" sizen="42 13" halign="center" valign="center" style="Bgs1InRace" substyle="BgTitle3_1"/>
      <label id="PluginTitleLabel" text="Labyz" posn="-138 82 1" halign="center" valign="center" style="TextTitle3"/>
      <quad id="PluginQuad" posn="-138 76 1" sizen="38 22" halign="center" valign="top" style="Bgs1" substyle="BgList" ScriptEvents="1"/>
      <quad id="PlaceQuad" posn="-138 60 4" sizen="30 6" halign="center" valign="center" style="Bgs1InRace" substyle="BgCard" ScriptEvents="1"/>
      <label id="PlaceLabel" text="Click me" posn="-138 60 4" halign="center" valign="center" style="TextButtonSmall" textsize="2"/>
    </frame>
  """;
  return MLText;
}

Void PlaceBlocks()
{
  declare CBlockModel BMArenaSimpleBase;
  BMArenaSimpleBase <=> BlockModels["ArenaSimpleBase"];
  RemoveAllBlocksAndTerrain();
  declare CoordYBaseSol = GetBlockGroundHeight(
    BMArenaSimpleBase, 19, 19, ::CardinalDirections::East);

  declare CGameCtnBlock B;
  PlaceBlock(BlockModels["RoadRaceToArenaMirror"], <3, CoordYBaseSol, 0>, ::CardinalDirections::East);
  B = GetBlock(<3, CoordYBaseSol-2, 0>);
  log(B == Null);
  B = GetBlock(<3, CoordYBaseSol-1, 0>);
  log(B == Null);
  B = GetBlock(<3, CoordYBaseSol, 0>);
  log(B == Null);
  B = GetBlock(<3, CoordYBaseSol+1, 0>);
  log(B == Null);
  B = GetBlock(<3, CoordYBaseSol+2, 0>);
  log(B == Null);
}

main()
{
  declare Boolean StartPlacing for ManialinkPage;
  ManialinkText = CreateManialink();
  while(True) {
    yield;
    if(StartPlacing) {
      PlaceBlocks();
      StartPlacing = False;
    }
  }
}
Don't forget to launch the debugger with CTRL-G when in script mode!

Re: ManiaScript Bug ?

Posted: 08 Sep 2011, 21:00
by SurferIX
Ok here's the problem:

If you remove all;

Code: Select all

  RemoveAllBlocksAndTerrain();
And just after that, you place a block:

Code: Select all

PlaceBlock(BlockModels["RoadRaceToArenaMirror"], <3, CoordYBaseSol, 0>, ::CardinalDirections::East);
Then you won't find it. This is the code that searches (almost) the whole map:

Code: Select all

  declare CGameCtnBlock B;
  log("- Searching... -");
  for (y, CoordYBaseSol-10, CoordYBaseSol+10) {
    for (z, 0, 30) {
      for (x, 0, 30) {
        B = GetBlock(<x, y, z>);
        if (B != Null) {
          if (B.BlockModel.Id != "Dirt") {
            log("" ^ x ^ ", " ^ y ^ ", " ^ z ^ " => " ^ B.BlockModel.Id);
          }
        }
      }
    }
  }
  log("- Done -");
So the solution is kinddof "force to draw and integrate changes": call "yield;"

Code: Select all

yield;
Then it works. I don't know if it normal or if it's a bug but you can very easily reproduce it.

Olivier.

Re: ManiaScript Bug ?

Posted: 08 Sep 2011, 21:02
by SurferIX
So this code without "yield;" doesn't work, with it, works: :1010

Code: Select all

Void PlaceBlocks()
{
  declare CBlockModel BMArenaSimpleBase;
  BMArenaSimpleBase <=> BlockModels["ArenaSimpleBase"];
  RemoveAllBlocksAndTerrain();
  declare CoordYBaseSol = GetBlockGroundHeight(
    BMArenaSimpleBase, 19, 19, ::CardinalDirections::East);

  PlaceBlock(BlockModels["RoadRaceToArenaMirror"], <3, CoordYBaseSol, 0>, ::CardinalDirections::East);
  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  yield;
  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  declare CGameCtnBlock B;
  log("- Searching... -");
  for (y, CoordYBaseSol-10, CoordYBaseSol+10) {
    for (z, 0, 30) {
      for (x, 0, 30) {
        B = GetBlock(<x, y, z>);
        if (B != Null) {
          if (B.BlockModel.Id != "Dirt") {
            log("" ^ x ^ ", " ^ y ^ ", " ^ z ^ " => " ^ B.BlockModel.Id);
          }
        }
      }
    }
  }
  log("- Done -");
}