We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Passing arrays as parameters to puzzles

Home Forums Programming Passing arrays as parameters to puzzles

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #13143
    scalare
    Customer

    Hello All,

    we need to pass a parameter to the puzzles with an array of object names through the runCode function, and have that array converted into a list that will drive a loop that will change the material for all those objects. Is there a way to do that through the puzzles? I mean, a way to convert the array into a list?

    Thank you!

    #13144
    jem
    Customer

    Hi scalre, sorry to hijack your question, but I am looking for something similar. I am passing multiple values into the puzzles through a runCode function, but each of those values passes via its own function parameter. This limits the number of values to a fixed quantity. The large number of parameters makes the function declaration inelegant.

    I would rather pass a single JSON string into my custom runCode function and parse that data in the puzzles. The parser would stuff the values from the JSON into block variables and arrays.

    I could write such a parser in JS and call it from a puzzle, but I tried this a few months ago and I could not make it work. As I recall, the problem was variable scoping. My parser script could not reference the variables is the visual_logic.js from the “main_app”.js I should revisit this again. It would be a useful tool.

    Jeremy Wernick

    #13146
    scalare
    Customer

    Hi Jem,

    yes, we were evaluating the possibility of editing a function inside the visual_logic.js, but then I thought I should ask here first, in case we were missing something. The JSON isn’t a bad idea, probably better since it would allow internal structure.

    #13149
    elk
    Customer

    Hi guys.

    I had a poke around in the code (still got a lot to learn about the verg3d/three.js codebase tho) but I made this little “snippet” that atleast work in the console with the app “class” exposed in Chrome and FF on my PC, did not test it in runCode tho;

    app.scene.getObjectByName(“Icosphere.001”).material = app.materials.find(x => x.name === “Material.003”);

    Replace “Icosphere.001” with your objects name, and “Material.003” with the material you want it to change too. You could just code a loop around this if you got the objects and materials listed in an array or JSON file or whatever.

    PS! The find method/function I just found on a quick search, and according to my findings it might be an EcmaScript6 thing, so might not be usable everywhere. So this is just to maybe point you in the right direction, and I suspect the Verge3D has a thing or to to correct me on for this single line of code :wacko: Atleast there should be a better way to get the material by name I suspect.

    I could not see the reason for getting it through the puzzle system tho, maybe elaborate on what you want to do, or why you need it to work a specific way.

    #13151
    elk
    Customer

    Also just realized there is a “make list from text <puzzle> with delimiter <puzzle>” puzzle. You should be able to then condense (concatinate) the entire array or JSON into a coma separated list (as one singe string/variable) for instance and pass that around as one variable either through JS calls or the load data for instance, if you got the data in a separate file.

    #13157

    I would rather pass a single JSON string into my custom runCode function and parse that data in the puzzles. The parser would stuff the values from the JSON into block variables and arrays.

    This is now possible thanks to Dictionary data type. This is a JSON-like structure that you can supply form JavaScript and parse with the puzzles.

    Chief 3D Verger | LinkedIn | Twitter

    #13333
    jem
    Customer

    Yuri,
    That is a great suggestion. I was able to pass a JSON object from the ExternalInterface JavaScript into the puzzles. The “in dict” dictionary puzzle parses the message into values. These values were then stored in local puzzle variables. This works for strings, numbers, and arrays. I will be using this technique in our work.

    For the others on this thread, here is my code and puzzles.

    function prepareExternalInterface(app) {
    	app.ExternalInterface.updateScene = function() {
            var jsonMessage = {"count" : 3, "color":"red", "object_names": ["sphere", "suzanne", "torus"]};
    		app.ExternalInterface.setValues(jsonMessage); 
        }
    }

    Jeremy Wernick

    #13343

    glad it helped!

    Chief 3D Verger | LinkedIn | Twitter

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.