Ogmo importing funkyness


(BlueZumbrellas) #1

Something I’ve been having trouble with over multiple flashpunk projects is being able to import the values of Booleans from ogmo files. They always come out as “true” regardless of how I parse it:

<blocks>
    <block_blue id="1" x="256" y="384" swappable="False" hasTimer="False" hasButton="False" switchType="circle" timerCounter="1" />
  </blocks>

			//Add blue blocks
		var blockList:XMLList = levelData.blocks.block_blue;
		
		for each (var bb:XML in blockList)
		{
			var hi:Boolean;
			
			hi = bb.@hasTimer;
			trace(hi);
		}

I’ve tried using Boolean(bb.@hasTimer) to type it but still the same result. Everything else seems to import correctly. Any help would be appreciated. Cheers.


(rostok) #2

what about

hi = bb.@hasTimer.toString()=="True";

?


(Jacob Albano) #3

Booleans in flash are kind of stupid.

new Boolean("true");	 //	true
new Boolean("false");	 //	true

The reason is that an empty string evaluates to false in as3, just like null and zero. When you pass a string to a boolean constructor, it checks to see if it’s empty, and otherwise returns true…even if that string is literally “true” or “True”.

Rostok’s solution above is the best approach in this situation.


(Zachary Lewis) #4

Gotta’ prevent case issues, too!

var myBoolean:Boolean = xmlNode.@myAttribute.toString().toLowerCase() == "true";

(Jacob Albano) #5

I think it’s safe enough in this case because Ogmo uses C#'s string format for booleans, so a bool value in an Ogmo level will always be either “True” or “False”.


(Nate ) #6

just do what I do, highlight the bit string up for questioning lol CTRL + H then change out the values you want with the proper values.


(Jacob Albano) #7

That solution isn’t particularly relevant in this case; Blue Zumbrellas is looking for help parsing values at runtime, and you’re talking about changing the file itself.


(BlueZumbrellas) #8

Thanks for the help, that fixed it, now I’ve got another xml/tilemap related issue: Save to string just plain doesn’t want to work:

levelTilemap = new Tilemap(TILEMAP_GFX1, tilemapWidth, tilemapHeight, tileSize, tileSize);
levelTilemap.x = FP.screen.width / 2 - levelTilemap.width / 2;
levelTilemap.y = FP.screen.height / 2 - levelTilemap.height / 2;
		
levelTilemap.setRect(0, 0, (tilemapWidth / tileSize), (tilemapWidth / tileSize), 1);

And I write this code to remove a space:

if (Input.pressed(Key.SPACE))
{
  levelTilemap.clearTile(cursor.x - levelTilemap.x, cursor.y - levelTilemap.y);
var newLevel:String = levelTilemap.saveToString();
trace(newLevel); //All 1's or 0's if map is completely empty, no -1 which should denote an empty space.
}

Have no idea what I’m doing wrong.