Trying to access pos.z in gold rush crashes tab

Playing gold rush, trying to access enemy.pos.z returns null

I could this.say(enemy.pos) and see the z attribute, but not access it through pos.z or pos[z]

I entered :
//get javascript object details

for(var propertyName in enemy.pos) {
sts+= propertyName;
sts+= “:”+ enemy.pos[propertyName]+". ";
}
this.say(sts);

to see how to access z and it crashed on compile. (as in - using chrome, I get the aw snap - crash page) Now It crashes every time, and cant access the code I wrote.

@nick, I’d really like that code .
and how do I get in to this level
and why cant I access Z

oh wait… I ran it in safari and it doesn’t crash.

so - reporting a bug that this crashes in chrome,

and wondering why I cant access pos.z

I think that code crashes because it’s 1) converting a ton of Vector function properties to strings, 2) concatenating all those together a ton of times into one long string, and 3) serializing a huge, constantly changing string from the web worker to the main thread once for every frame of the simulation. So the code is slow and unperformant because of 1) and 2), but probably step 3) is what is crashing it, because my serialization code can’t handle so many huge strings getting sent across the web worker boundary at once.

The reason you can’t access z is because it’s not in the Vector’s API, since we intended that all the gameplay be basically in 2D and have the z-dimension just be aesthetic for almost all cases. Are you trying to use it just to see if the enemy is jumping, or is there another use case for knowing it?

yes, its to see if hes jumping

You can save his current position in this.enemyLastPos and compare distance the following frame. If his distance is greater than his movement speed provides (not sure what it is off hand) then he would be jumping. If it’s lower, he might be jumping, but using it ineffectively.

Okay so I am having something weird happen, and I can not for the life of me figure out why.

I am trying to run this code, and it tells me it “can’t read property ‘pos’ of undefined”.

var items = this.getItems();
items.sort(function (a, b) {
	if(a.bountyGold < b.bountyGold) {
		return -1;
	} else if(a.bountyGold > b.bountyGold) {
		return 1;
	} else if(a.bountyGold == b.bountyGold) {
		if(a.distance(this) > b.distance(this)) {
			return -1;
		}
		if(a.distance(this) < b.distance(this)) {
			return 1;
		}
	}
	return 0;
});
items.reverse();
if(items[0]) {
	this.move(items[0].pos);
} else {
	this.moveXY(18, 36);
}

Alright I just found out this is what comes up in the debugger. Is this supposed to be happening?

I think what’s going on is that this is no longer Tharin inside your sort callback–it’s the anonymous sort function. So when you call a.distance(this), it tries to find pos on this, but this (the sort function) has no pos. You could do something like this:

var tharin = this;
items.sort(function(a, b) {
    // ...
    if(a.distance(tharin) > b.distance(tharin)) {
    // ...

Hope this helps.

Alright, so here’s my code now:

var items = this.getItems();
items.sort(function(a, b) {
	if (a.bountyGold < b.bountyGold) {
		return -1;
	}
	else if (a.bountyGold > b.bountyGold) {
		return 1;
	}
	else if (a.bountyGold == b.bountyGold) {
		if (a.distance(tharin) > b.distance(tharin)) {
			return -1;
		}
		if (a.distance(tharin) < b.distance(tharin)) {
			return 1;
		}
	}
	return 0;
});
items.reverse();
if (items[0]) {
	this.move(items[0].pos);
}
else {
	this.moveXY(18, 36);
}

Using this, I get an error:

Works if you add this line at the top:

var tharin = this;

Yeah, I edited that post because I got it to work, but something went wrong because it’s not edited. Oh well, thanks for your help though!

also, on a side note:
items.reverse is not needed. Just swap over the return 1 / return -1 in your sort function.