You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current code comments and old tutorials say that you need to initialize ensemble by calling ensemble.init(), but removing it from our sampleGame doesn't break anything, and the code doesn't look like it does anything:
So any "initialTimeStep" passed as a parameter does not get passed along to socialRecord.init() to initialize the timestep to a particular number. Which means initialTimeStep is always undefined and no code actually runs except return "OK";.
Short story: we could just ignore or delete ensemble.init() and everything will be fine. You can't initialize Ensemble with a different starting time step, but you could achieve essentially the same thing with ensemble.setupNextTimeStep(timestep).
Long story:
If we edit ensemble.init() so that a timestep parameter passed to it is passed on to socialRecord.init(), we create some unintended consequences when we set the initial timestep to anything that isn't 0 or -1 using ensemble.init(timestep). Running with the Lovers and Rivals project (in sampleGame) (with the above modification to ensemble.js) for example, your history won't load and you'll get Uncaught TypeError: Cannot read property 'push' of undefined for the socialRecord[timeStep].push(socialRecordPredicate); (described below).
Based on a cursory look, it seems as though set() (the function to save a "predicate" or piece of state to the socialRecord at the current timestep, as called from addHistory()) will break if the current timestep cannot act as an index into the socialRecord array. This will happen if you initialize the time step to 7, for example, and the loaded history.json has only 1 pos object. Eg.,
will try to push the new predicate to the array of predicates at the current time index of the socialRecord array. Normally, the first time this is called, socialRecord will be equal to an array with exactly one empty array in it, or [Array(0)] according to Chrome console formatting. And the timeStep will be 0, so it will successfully push the predicate to that empty array. And so on for the rest of the history.
But if we call ensemble.init(7) before loading the history, the first time set() is invoked (by addHistory(), socialRecord will be [empty, Array(0), Array(0), Array(0), Array(0), Array(0), Array(0), Array(0)]. The timestep will still be 0 (which I found surprising—why not 7? Maybe it increments for every pos object in history.json). So socialRecord[0] will not be something you can push to, because it's empty not an array of zero length. Hence the Uncaught TypeError: Cannot read property 'push' of undefined error.
This is all to say that ensemble.init() isn't currently doing anything and it isn't trivial to make it do something at this point.
The text was updated successfully, but these errors were encountered:
This is a really good catch – it never would've occurred to me to check this. IMO, based on what you've said here, we should probably just remove the ensemble.init() function entirely.
The current code comments and old tutorials say that you need to initialize ensemble by calling
ensemble.init()
, but removing it from our sampleGame doesn't break anything, and the code doesn't look like it does anything:The public ensemble.init() function definition:
where
socialRecord.init
is defined as:So any "initialTimeStep" passed as a parameter does not get passed along to socialRecord.init() to initialize the timestep to a particular number. Which means
initialTimeStep
is always undefined and no code actually runs exceptreturn "OK";
.Short story: we could just ignore or delete
ensemble.init()
and everything will be fine. You can't initialize Ensemble with a different starting time step, but you could achieve essentially the same thing withensemble.setupNextTimeStep(timestep)
.Long story:
If we edit
ensemble.init()
so that a timestep parameter passed to it is passed on tosocialRecord.init()
, we create some unintended consequences when we set the initial timestep to anything that isn't 0 or -1 usingensemble.init(timestep)
. Running with the Lovers and Rivals project (insampleGame
) (with the above modification to ensemble.js) for example, your history won't load and you'll getUncaught TypeError: Cannot read property 'push' of undefined
for thesocialRecord[timeStep].push(socialRecordPredicate);
(described below).Based on a cursory look, it seems as though
set()
(the function to save a "predicate" or piece of state to the socialRecord at the current timestep, as called fromaddHistory()
) will break if the current timestep cannot act as an index into thesocialRecord
array. This will happen if you initialize the time step to 7, for example, and the loadedhistory.json
has only 1pos
object. Eg.,Then the following line in
set()
(1740 of standalone ensemble.js or 506 of socialRecord.js)will try to push the new predicate to the array of predicates at the current time index of the socialRecord array. Normally, the first time this is called,
socialRecord
will be equal to an array with exactly one empty array in it, or[Array(0)]
according to Chrome console formatting. And the timeStep will be 0, so it will successfully push the predicate to that empty array. And so on for the rest of the history.But if we call
ensemble.init(7)
before loading the history, the first timeset()
is invoked (byaddHistory()
,socialRecord
will be[empty, Array(0), Array(0), Array(0), Array(0), Array(0), Array(0), Array(0)]
. Thetimestep
will still be 0 (which I found surprising—why not 7? Maybe it increments for everypos
object inhistory.json
). SosocialRecord[0]
will not be something you can push to, because it'sempty
not an array of zero length. Hence theUncaught TypeError: Cannot read property 'push' of undefined
error.This is all to say that
ensemble.init()
isn't currently doing anything and it isn't trivial to make it do something at this point.The text was updated successfully, but these errors were encountered: