MCPcopy Index your code
hub / github.com/4ian/GDevelop / loadVariableFromJSONFile

Function loadVariableFromJSONFile

Extensions/FileSystem/filesystemtools.ts:449–475  ·  view source on GitHub ↗
(
      variable: gdjs.Variable,
      loadPath: string,
      resultVar: gdjs.Variable,
      removeCRCharacters: boolean
    )

Source from the content-addressed store, hash-verified

447 * @param removeCRCharacters If true, will remove \r characters usually added by Windows when editing files
448 */
449 export const loadVariableFromJSONFile = function (
450 variable: gdjs.Variable,
451 loadPath: string,
452 resultVar: gdjs.Variable,
453 removeCRCharacters: boolean
454 ) {
455 let result = 'error';
456 if (fs) {
457 try {
458 const data = fs.readFileSync(loadPath, 'utf8');
459 if (data) {
460 variable.fromJSON(
461 removeCRCharacters ? data.replace(/\r/g, '') : data
462 );
463 result = 'ok';
464 }
465 } catch (err) {
466 logger.error(
467 "Unable to load variable from the file at path: '" +
468 loadPath +
469 "': ",
470 err
471 );
472 }
473 }
474 resultVar.setString(result);
475 };
476
477 /**
478 * Load a JSON file and convert it into a variable, asynchronously.

Callers

nothing calls this directly

Calls 4

replaceMethod · 0.80
errorMethod · 0.65
fromJSONMethod · 0.45
setStringMethod · 0.45

Tested by

no test coverage detected