Created
October 22, 2013 17:35
-
-
Save bennlich/7104763 to your computer and use it in GitHub Desktop.
die() behavior with while loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count = 0; | |
while (agent.patchRightAndAhead(0,1).isWall()) { | |
agent.rotate(Math.PI/2); | |
count++; | |
if (count >= 3) { | |
agent.die(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.