Invalid Field Access?

255 views
Skip to first unread message

NullBackspace

unread,
Aug 17, 2015, 8:12:44 PM8/17/15
to HaxeFlixel
Hello fellow haxeflixel devs,

I ran into an error while running the Neko debug for my game. Here is the error:

Invalid field access : x
Called from PlayState::enemyRandomPlacement line 149
Called from PlayState::create line 84
Called from flixel.FlxGame::switchState line 583
Called from flixel.FlxGame::update line 668
Called from flixel.FlxGame::step line 648
Called from flixel.FlxGame::onEnterFrame line 493
Called from openfl._legacy.events.EventDispatcher::dispatchEvent line 98
Called from openfl._legacy.display.DisplayObject::__dispatchEvent line 182
Called from openfl._legacy.display.DisplayObject::__broadcast line 161
Called from openfl._legacy.display.DisplayObjectContainer::__broadcast line 280
Called from openfl._legacy.display.Stage::__render line 1074
Called from openfl._legacy.display.Stage::__checkRender line 339
Called from openfl._legacy.display.Stage::__pollTimers line 1059
Called from openfl._legacy.display.Stage::__doProcessStageEvent line 414

Here is the code in question:

override public function create():Void 
{
super.create();
tileMap = new FlxTilemap();
tileMap.loadMap(Assets.getText("assets/data/map.csv"), AssetPaths.tile1__png, TILE_WIDTH, TILE_HEIGHT, 0, 1);
tileMap.setTileProperties(0, FlxObject.ANY);
tileMap.setTileProperties(1, FlxObject.ANY);
tileMap.setTileProperties(2, FlxObject.NONE);
FlxG.worldBounds.set(0, 0, tileMap.width, tileMap.height);
cameraFocus = new FlxSprite();
cameraFocus.makeGraphic(1, 1, FlxColor.TRANSPARENT);
camera = FlxG.camera;
camera.follow(cameraFocus, FlxCamera.STYLE_LOCKON);
hero = new Player();
//Enemy Addition
grpEnemies = new FlxGroup();
var i:Int = 0;
while (i != FlxRandom.intRanged(5, 8))
{
enemyRandomPlacement(0, 0, 0);
enemyRandomPlacement(0, 0, 1);
i++;
}
//Hero addition
randomPlacement();
//Addition to state
add(tileMap);
add(cameraFocus);
add(hero);
add(movementMarker);
add(grpEnemies);
}

enemyRandomPlacement:

private function enemyRandomPlacement(x:Int, y:Int, etype:Int):Void
{
var enemy:Enemy = new Enemy(x, y, etype);
var emptyTiles:Array<FlxPoint> = tileMap.getTileCoords(2, false);
var randomEmptyTile:FlxPoint = emptyTiles[FlxRandom.intRanged(0, emptyTiles.length)];
enemy.setPosition(randomEmptyTile.x, randomEmptyTile.y);
grpEnemies.add(enemy);
}

I can't figure out what's wrong with it. Any solutions?

MegaLeon

unread,
Aug 18, 2015, 2:24:04 AM8/18/15
to HaxeFlixel
Which one is line 149 on enemyRandomPlacement?

NullBackspace

unread,
Aug 18, 2015, 10:55:37 AM8/18/15
to haxef...@googlegroups.com
Line 84:

enemyRandomPlacement
(0, 0, 0);
Line 149:

enemy.setposition(randomEmptyTile.x, randomEmptyTile.y)

Also, the function is similar to the one used in FlxCaveGenerator. It works for the player placement, but for some reason, it does not work for enemies. The error does not always show up too, which is odd.

Sebastian Fernandez

unread,
Aug 19, 2015, 8:35:02 AM8/19/15
to HaxeFlixel
FlxRandom.intRanged(0, emptyTiles.length) gives you a number between 0 and emptyTiles.length. I guess you're getting the 'emptyTiles.length' number, which is out of bound of emptyTiles. Try calling intRanged(0, length-1).

NullBackspace

unread,
Aug 19, 2015, 10:44:56 AM8/19/15
to HaxeFlixel
K I figured it out. I used trace to see what the points were. For some reason, the loop for placing entities kept on going. I placed a break if the counter went over the maximum int. Thanks for the advice though!
Reply all
Reply to author
Forward
0 new messages