JSON

K.V.
14 Dec 2017, 07:04

Hello, Quest Forum!

So...

I tried to make Quest JS run under Linux, to no avail.

I tried to look at Quest JS's source code to come up with some workaround. Again, no results worth mentioning.

I found a script to convert XML to JSON. It will convert an .aslx file with a quick extension rename to .xml.

It looks like a JSON object thingy, but I can't figure out how to access anything in it to convert the objects to JS.

Anyone have any links or info concerning such things?


I guess I should post some code...

//Placeholder

-=Darchy=-
14 Dec 2017, 10:39

I may be misunderstanding as I usually am at my age, but is this the sort of thing you mean?:

https://json-to-js.com/


K.V.
14 Dec 2017, 14:11

Thanks!

JSON

{"asl":{"$":{"version":"550"},"include":[{"$":{"ref":"English.aslx"}},{"$":{"ref":"Core.aslx"}}],"game":[{"$":{"name":"a jar"},"gameid":["afadb32b-5937-43f9-b109-2b802cd508ff"],"version":["1.0"],"firstpublished":["2017"],"appendobjectdescription":[""]}],"object":[{"$":{"name":"room"},"inherit":[{"$":{"name":"editor_room"}}],"object":[{"$":{"name":"player"},"inherit":[{"$":{"name":"editor_object"}},{"$":{"name":"editor_player"}}]},{"$":{"name":"door"},"inherit":[{"$":{"name":"editor_object"}},{"$":{"name":"openable"}},{"$":{"name":"container_lockable"}}],"feature_container":[""],"keycount":[{"_":"1","$":{"type":"int"}}],"inroomdescription":["{either door.isopen: The door is now open.| The door is closed at the moment.}"],"key":[{"_":"Skellington Key","$":{"type":"object"}}],"look":[{"_":"\r\n        if (door.isopen) {\r\n          msg (\"The door is ajar.\")\r\n        }\r\n        else {\r\n          msg (\"The door is closed.\")\r\n        }\r\n      ","$":{"type":"script"}}],"openscript":[{"_":"\r\n        if (this.locked) {\r\n          if (this.autounlock and AllKeysAvailable(this)) {\r\n            do (this, \"unlock\")\r\n            if (not this.isopen) {\r\n              OpenObject (this)\r\n            }\r\n          }\r\n          else {\r\n            msg (DynamicTemplate(\"LockedObject\", this))\r\n          }\r\n        }\r\n        else {\r\n          OpenObject (this)\r\n        }\r\n      ","$":{"type":"script"}}],"exit":[{"$":{"alias":"up","to":"room"},"inherit":[{"$":{"name":"updirection"}}]}]},{"$":{"name":"Skellington Key"},"inherit":[{"$":{"name":"editor_object"}},{"$":{"name":"wearable"}}],"take":[""],"lookedatonce":[{"_":"false","$":{"type":"boolean"}}],"look":[{"$":{"type":"script"}}],"ontake":[{"_":"\r\n        msg (\"Taken.\")\r\n      ","$":{"type":"script"}}],"feature_wearable":[""]}],"exit":[{"$":{"name":"lockeddoor1","alias":"in","to":"another room"},"inherit":[{"$":{"name":"indirection"}}],"locked":[""],"lockmessage":["The door is locked."],"runscript":[{"_":"false","$":{"type":"boolean"}}],"script":[{"$":{"type":"script"}}]}]},{"$":{"name":"another room"},"inherit":[{"$":{"name":"editor_room"}}],"exit":[{"$":{"name":"locked door","alias":"out","to":"room"},"inherit":[{"$":{"name":"outdirection"}}],"locked":[""]}]}]}}

After converting to JS:

{
  asl: {
    $: {
      version: '550',
    },
    include: [
      {
        $: {
          ref: 'English.aslx',
        },
      },
      {
        $: {
          ref: 'Core.aslx',
        },
      },
    ],
    game: [
      {
        $: {
          name: 'a jar',
        },
        gameid: [
          'afadb32b-5937-43f9-b109-2b802cd508ff',
        ],
        version: [
          '1.0',
        ],
        firstpublished: [
          '2017',
        ],
        appendobjectdescription: [
          '',
        ],
      },
    ],
    object: [
      {
        $: {
          name: 'room',
        },
        inherit: [
          {
            $: {
              name: 'editor_room',
            },
          },
        ],
        object: [
          {
            $: {
              name: 'player',
            },
            inherit: [
              {
                $: {
                  name: 'editor_object',
                },
              },
              {
                $: {
                  name: 'editor_player',
                },
              },
            ],
          },
          {
            $: {
              name: 'door',
            },
            inherit: [
              {
                $: {
                  name: 'editor_object',
                },
              },
              {
                $: {
                  name: 'openable',
                },
              },
              {
                $: {
                  name: 'container_lockable',
                },
              },
            ],
            feature_container: [
              '',
            ],
            keycount: [
              {
                _: '1',
                $: {
                  type: 'int',
                },
              },
            ],
            inroomdescription: [
              '{either door.isopen: The door is now open.| The door is closed at the moment.}',
            ],
            key: [
              {
                _: 'Skellington Key',
                $: {
                  type: 'object',
                },
              },
            ],
            look: [
              {
                _: '\r\n        if (door.isopen) {\r\n          msg ("The door is ajar.")\r\n        }\r\n        else {\r\n          msg ("The door is closed.")\r\n        }\r\n      ',
                $: {
                  type: 'script',
                },
              },
            ],
            openscript: [
              {
                _: '\r\n        if (this.locked) {\r\n          if (this.autounlock and AllKeysAvailable(this)) {\r\n            do (this, "unlock")\r\n            if (not this.isopen) {\r\n              OpenObject (this)\r\n            }\r\n          }\r\n          else {\r\n            msg (DynamicTemplate("LockedObject", this))\r\n          }\r\n        }\r\n        else {\r\n          OpenObject (this)\r\n        }\r\n      ',
                $: {
                  type: 'script',
                },
              },
            ],
            exit: [
              {
                $: {
                  alias: 'up',
                  to: 'room',
                },
                inherit: [
                  {
                    $: {
                      name: 'updirection',
                    },
                  },
                ],
              },
            ],
          },
          {
            $: {
              name: 'Skellington Key',
            },
            inherit: [
              {
                $: {
                  name: 'editor_object',
                },
              },
              {
                $: {
                  name: 'wearable',
                },
              },
            ],
            take: [
              '',
            ],
            lookedatonce: [
              {
                _: 'false',
                $: {
                  type: 'boolean',
                },
              },
            ],
            look: [
              {
                $: {
                  type: 'script',
                },
              },
            ],
            ontake: [
              {
                _: '\r\n        msg ("Taken.")\r\n      ',
                $: {
                  type: 'script',
                },
              },
            ],
            feature_wearable: [
              '',
            ],
          },
        ],
        exit: [
          {
            $: {
              name: 'lockeddoor1',
              alias: 'in',
              to: 'another room',
            },
            inherit: [
              {
                $: {
                  name: 'indirection',
                },
              },
            ],
            locked: [
              '',
            ],
            lockmessage: [
              'The door is locked.',
            ],
            runscript: [
              {
                _: 'false',
                $: {
                  type: 'boolean',
                },
              },
            ],
            script: [
              {
                $: {
                  type: 'script',
                },
              },
            ],
          },
        ],
      },
      {
        $: {
          name: 'another room',
        },
        inherit: [
          {
            $: {
              name: 'editor_room',
            },
          },
        ],
        exit: [
          {
            $: {
              name: 'locked door',
              alias: 'out',
              to: 'room',
            },
            inherit: [
              {
                $: {
                  name: 'outdirection',
                },
              },
            ],
            locked: [
              '',
            ],
          },
        ],
      },
    ],
  },
}

K.V.
14 Dec 2017, 15:57

This is pretty cool!

So far, I've got this:

(Excerpt from objectPuller.js)

EDITED

var addText = console.log;
var msg = addText;

msg('Game name:');
msg(asl.asl.game[0].$.name);
msg('');
msg('Game ID:');
msg(asl.asl.game[0].gameid[0]);
var theAsl = asl.asl;
var objects = asl.asl.object;
var objectOne = objects[0].object;
var objectOneName = objects[0].$.name;

msg('');
msg('Things in theAsl:');
msg('');
//var i = 0;
//var num = 0;
var thisNum = 0;
for (var stuff in theAsl){
	thisNum++;
	//num++;
	//if(theAsl.hasOwnProperty(stuff)){
		//i++;		
	//}
	msg('');
	msg('Type: '+typeof theAsl[stuff])
	msg(typeof theAsl[stuff]+''+thisNum);
	msg(theAsl[stuff]);
	
	msg('');
	msg('nested in '+typeof theAsl[stuff]+''+thisNum+':');
	for (var moreStuff in theAsl[stuff]){
		msg('Type: '+typeof theAsl[stuff][moreStuff]);
		msg(theAsl[stuff][moreStuff]);
	};
};
//msg(i);
//msg(num);
//msg(Object.keys(theAsl).length);
msg('');
msg('Things in objects:');
for(var things in objects){
	msg(objects[things].$.name);
};
msg('');
msg('Things in '+objectOneName+':');
for (var key in objectOne) {
  msg(objectOne[key].$.name);
};
msg('');

I run node objectPuller.js, and I get this:

Game name:
a jar

Game ID:
afadb32b-5937-43f9-b109-2b802cd508ff

Things in theAsl:


Type: object
object1
{ version: '550' }

nested in object1:
Type: string
550

Type: object
object2
[ { '$': { ref: 'English.aslx' } },
  { '$': { ref: 'Core.aslx' } } ]

nested in object2:
Type: object
{ '$': { ref: 'English.aslx' } }
Type: object
{ '$': { ref: 'Core.aslx' } }

Type: object
object3
[ { '$': { name: 'a jar' },
    gameid: [ 'afadb32b-5937-43f9-b109-2b802cd508ff' ],
    version: [ '1.0' ],
    firstpublished: [ '2017' ],
    appendobjectdescription: [ '' ] } ]

nested in object3:
Type: object
{ '$': { name: 'a jar' },
  gameid: [ 'afadb32b-5937-43f9-b109-2b802cd508ff' ],
  version: [ '1.0' ],
  firstpublished: [ '2017' ],
  appendobjectdescription: [ '' ] }

Type: object
object4
[ { '$': { name: 'room' },
    inherit: [ [Object] ],
    object: [ [Object], [Object], [Object] ],
    exit: [ [Object] ] },
  { '$': { name: 'another room' },
    inherit: [ [Object] ],
    exit: [ [Object] ] } ]

nested in object4:
Type: object
{ '$': { name: 'room' },
  inherit: [ { '$': [Object] } ],
  object: 
   [ { '$': [Object], inherit: [Object] },
     { '$': [Object],
       inherit: [Object],
       feature_container: [Object],
       keycount: [Object],
       inroomdescription: [Object],
       key: [Object],
       look: [Object],
       openscript: [Object],
       exit: [Object] },
     { '$': [Object],
       inherit: [Object],
       take: [Object],
       lookedatonce: [Object],
       look: [Object],
       ontake: [Object],
       feature_wearable: [Object] } ],
  exit: 
   [ { '$': [Object],
       inherit: [Object],
       locked: [Object],
       lockmessage: [Object],
       runscript: [Object],
       script: [Object] } ] }
Type: object
{ '$': { name: 'another room' },
  inherit: [ { '$': [Object] } ],
  exit: [ { '$': [Object], inherit: [Object], locked: [Object] } ] }

Things in objects:
room
another room

Things in room:
player
door
Skellington Key



I can simplify that script to make it iterate through everything. I just need to take a short break and drink some orange juice first.

(I'll pop back in before continuing, just to make sure no one has posted anything crafty. (KV clears his throat.))


Thanks, again, Darchy!

There was a veritable cornucopia of similar converters, but this one was just what I needed!


-=Darchy=-
14 Dec 2017, 22:52

My pleasure K.V - It feels good to have been able to repay for your assistance. Did you grab the download version at the bottom of the page?

-=Darchy=-


K.V.
14 Dec 2017, 23:15

Oh yeah, I grabbed that as soon as I saw it, but I'm being lazy and using the online version at the moment.

Thanks much!


Here's what I've got going on (or ALMOST going on) right now:

(I posted the source JSON object earlier in this thread.)

My "script":


var addText = console.log;
var msg = addText;

msg('Game name:');
msg(asl.asl.game[0].$.name);
msg('');
msg('Game ID:');
msg(asl.asl.game[0].gameid[0]);

var theAsl = asl.asl;
var objects = asl.asl.object;
var objectOne = objects[0].object;
var objectOneName = objects[0].$.name;

msg('');

msg('');
//var i = 0;
//var num = 0;
var thisNum = 0;

var mainObjects = [];
var subObjects = [];

function iterateThru(obj){
    for(var prop in obj){
        if(obj.hasOwnProperty(prop)){
		    mainObjects.push(prop+': '+obj[prop]);
		}
    }
	for (var typeVar in mainObjects){
		if(mainObjects.hasOwnProperty(typeVar)){
		    subObjects.push(typeVar+': '+mainObjects[typeVar]);
		}
	}
	msg('=======mainObjects========');
	for(var eachThing in mainObjects){
	    msg(eachThing+': '+mainObjects[eachThing]);	
	}
	msg('-------END OF mainObjects------');
	msg('');
	msg('========subObjects=========');
	for(var moreThings in subObjects){
		msg(moreThings+': '+subObjects[moreThings]);
	}
	msg('----------END OF subObjects-------');
}
msg('==============iterateThru==================');
for(var key in objects){
    iterateThru(objects[key]);
}

//msg(iterateThru(theAsl));
msg('---------end of iterateThru---------');



msg('------FOR STUFF IN THEASL---------');
for (var key in theAsl){
	msg('');
	msg('key: '+key);
	//num++;
	//if(theAsl.hasOwnProperty(key)){
		//i++;		
	//}
	msg('');
	msg('Type: '+typeof theAsl[key])

	msg(key+': '+theAsl[key]);
	
	msg('');
	msg('nested in '+key+':');
	for (var newKey in theAsl[key]){
		msg('');
		msg('newKey: '+newKey);
		msg('');
		msg('Type: '+typeof theAsl[key][newKey]);
		msg(theAsl[key][newKey]);
		msg('');
	};
};
msg('------END OF FOR STUFF IN THEASL---------');


msg('');

msg('---------Things in objects---------');
for(var things in objects){
	msg(objects[things].$.name);
};
msg('------END OF Things in objects---------');

msg('');

msg('---------Things in '+objectOneName+' (Things in objectOneName)---------');
for (var key in objectOne) {
  msg(objectOne[key].$.name);
};
msg('');
msg('------END OF Things in objectOneName---------');

The output:

Game name:
a jar

Game ID:
afadb32b-5937-43f9-b109-2b802cd508ff


==============iterateThru==================
=======mainObjects========
0: $: [object Object]
1: inherit: [object Object]
2: object: [object Object],[object Object],[object Object]
3: exit: [object Object]
-------END OF mainObjects------

========subObjects=========
0: 0: $: [object Object]
1: 1: inherit: [object Object]
2: 2: object: [object Object],[object Object],[object Object]
3: 3: exit: [object Object]
----------END OF subObjects-------
=======mainObjects========
0: $: [object Object]
1: inherit: [object Object]
2: object: [object Object],[object Object],[object Object]
3: exit: [object Object]
4: $: [object Object]
5: inherit: [object Object]
6: exit: [object Object]
-------END OF mainObjects------

========subObjects=========
0: 0: $: [object Object]
1: 1: inherit: [object Object]
2: 2: object: [object Object],[object Object],[object Object]
3: 3: exit: [object Object]
4: 0: $: [object Object]
5: 1: inherit: [object Object]
6: 2: object: [object Object],[object Object],[object Object]
7: 3: exit: [object Object]
8: 4: $: [object Object]
9: 5: inherit: [object Object]
10: 6: exit: [object Object]
----------END OF subObjects-------
---------end of iterateThru---------
------FOR STUFF IN THEASL---------

key: $

Type: object
$: [object Object]

nested in $:

newKey: version

Type: string
550


key: include

Type: object
include: [object Object],[object Object]

nested in include:

newKey: 0

Type: object
{ '$': { ref: 'English.aslx' } }


newKey: 1

Type: object
{ '$': { ref: 'Core.aslx' } }


key: game

Type: object
game: [object Object]

nested in game:

newKey: 0

Type: object
{ '$': { name: 'a jar' },
  gameid: [ 'afadb32b-5937-43f9-b109-2b802cd508ff' ],
  version: [ '1.0' ],
  firstpublished: [ '2017' ],
  appendobjectdescription: [ '' ] }


key: object

Type: object
object: [object Object],[object Object]

nested in object:

newKey: 0

Type: object
{ '$': { name: 'room' },
  inherit: [ { '$': [Object] } ],
  object: 
   [ { '$': [Object], inherit: [Object] },
     { '$': [Object],
       inherit: [Object],
       feature_container: [Object],
       keycount: [Object],
       inroomdescription: [Object],
       key: [Object],
       look: [Object],
       openscript: [Object],
       exit: [Object] },
     { '$': [Object],
       inherit: [Object],
       take: [Object],
       lookedatonce: [Object],
       look: [Object],
       ontake: [Object],
       feature_wearable: [Object] } ],
  exit: 
   [ { '$': [Object],
       inherit: [Object],
       locked: [Object],
       lockmessage: [Object],
       runscript: [Object],
       script: [Object] } ] }


newKey: 1

Type: object
{ '$': { name: 'another room' },
  inherit: [ { '$': [Object] } ],
  exit: [ { '$': [Object], inherit: [Object], locked: [Object] } ] }

------END OF FOR STUFF IN THEASL---------

---------Things in objects---------
room
another room
------END OF Things in objects---------

---------Things in room (Things in objectOneName)---------
player
door
Skellington Key

------END OF Things in objectOneName---------


I don't know what I've done to iterateThru, but the second method seems to be something I can work with.


jmnevil54
14 Dec 2017, 23:27

So are you working with JSON to further your "make an alternative save system" plans, or are you still trying to put JSON, html, and more codes into Quest?


K.V.
14 Dec 2017, 23:58

are you working with JSON to further your "make an alternative save system" plans

I'm trying to make a Quest game run in Linux or Mac.

I can download wine, winetricks, and dotnet40 and get Quest to create a game in Linux, but it won't play any games.

Quest JS just compiles Quest games into web sites (HTML, CSS, and JS files), but it won't run in the same environment as Quest, and I can't find a way to even get Quest JS to open outside of Windows at all.

...but I think Quest JS is just converting the XML to JS anyway, so I'm trying to make it work with NodeJS.


I think that was Anonynn who was trying to come up with an alternative save system, but I'm pretty sure she just decided to use Pixie's Save/Load thing.


are you still trying to put JSON, html, and more codes into Quest?

Always, ma'am. Always.


jmnevil54
15 Dec 2017, 02:30

Oh.
I wonder if anyone is trying to put those extra codes into the online version of Quest...


K.V.
15 Dec 2017, 02:49

Which ones?

I've been doing most of my stuff in the online player recently, so it should work.

When pasting JS.eval() stuff:

Instead of entering code view, just select Javascript from the menu (it's the last one in the first screen, where you can print a message), and paste everything after JS. into the text input field. If you try pasting (or editing) anything in code view, it messes up 99% of the time.


K.V.
15 Dec 2017, 03:09

UPDATE

It won't let me post the JS code here anymore, but here's the link to the Gist:

https://gist.github.com/KVonGit/3ed552fce5010427e7d9dbeb5eebea6c


I'm getting it figured out, slowly.

It looks like an object is named $ and a script is _. Then, each has a name string (or array) set up, along with all the other good stuff.