Skip to content

Instantly share code, notes, and snippets.

@bennlich
Created October 22, 2013 17:35
Show Gist options
  • Save bennlich/7104763 to your computer and use it in GitHub Desktop.
Save bennlich/7104763 to your computer and use it in GitHub Desktop.
die() behavior with while loop
var count = 0;
while (agent.patchRightAndAhead(0,1).isWall()) {
agent.rotate(Math.PI/2);
count++;
if (count >= 3) {
agent.die();
}
}
@backspaces
Copy link

Makes a lot of sense, and indeed I seem to run into it too. Yet another reference vs value thing.

Unfortunately, agent is a local variable and there's no way for AS or another program to change it. AS could convert it to a "phantom" agent, i.e. the reference "agent" could somehow hollow itself out after the die call, then the GC would eventually get rid of it.

Wait tho, I see what you're saying .. is there a way to delete an instance so to speak. Have you tried it in a snippet? It is a cool idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment