APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

unserialize problem with boolean variables

Return to the EJS Modeling forum
Login to post to this thread

unserialize problem with boolean variables Ejss
John Val
13 Posts

Dera all,

I tried to set boolean values with the function

_model._userUnserialize

function present in the simulation js file

This does not work since in this function does the following

    if(json.flag) flag = json.flag;

now if you set the value in the json string as "flag":false

this line reulst in not setting flag to false since json.flag is set to be false!!!

In the next version of EJS this should be rewritten to

    if(! (json.flag===null) ) flag = json.flag;

I now have written my own unserialize function for flags which you can put in you custom function which you should call before calling the _model._userUnserialize or model unserialize function in your javascript

model custo functions:

_model.unserializeFlags = function(json) {
    if(! (json.flag ===null )) flag= json.flag;
   _model.update();
};

in your exernal script you than call

_model.unserializeFlags(ejsjsonflags);
_model.unserialize(ejsjson);


John


Current Replies - View all
Re: unserialize problem w...   (Francisco Esquembre - )
Re: Re: unserialize probl...   (John Val - )
OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book