For background, I am currently playing through Untrusted, a JavaScript-based programming game whose core mechanic is editing code to modify the game world to progress forward. I have solved most levels the "intended" way by modifying the variables I am given in the local scope using the documented in-game API. However, I am wondering if there are also some "unintended" ways to modify the game state/game definition by fishing around.
A lot of the game has code as follows (evaluated in window
scope):
function foo() {
var bar = 1234;
}
I understand that I can access foo
from any scope by referring to window.foo
. Is there a way I can access bar
inside foo
even though it is not explicitly exposed?
To clarify, the above code is already evaluated for me (in window
scope, I believe, so I can at least get a reference to the foo
). I can not change what is evaluated. (I suppose I could redefine foo
if I really wanted, and that would bypass a lot of restrictions, but that's tangential to the current direction of questioning.) Rather, my goal is, given this has already been evaluated, modify it in place (such as setting a new value for bar
).
Thanks in advance!