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.

Dynamic calls to procedures

Home Forums Puzzles Dynamic calls to procedures

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #18990
    scalare
    Customer

    Hello, continuing with our requests for dynamic functionality here :bye: :

    The puzzles provide a way to create a procedure, and after you do it, the procedure is added to the procedures tab for you to select and drag to call it whenever you need. However, if you have many different procedures, and you need to call them based on a parameter received from outside the viewport (via javascript) there is no dynamic way to call it. Let’s say you have a variable that you set with the name of a procedure. There is no way to call that procedure using that variable name. You have to ask for the variable value, and call the corresponding procedure using one of the pre-defined calls from the procedure tab.

    Would a dynamic call make sense like it did for the dynamic parameters for sounds, textures for the replace texture and values for set value puzzles?

    Thank you! :)

    #18995

    Hi,

    Something like this is possible now with logic puzzles. Is it what you’re looking for?

    Attachments:
    You must be logged in to view attached files.

    Chief 3D Verger | LinkedIn | Twitter

    #18999
    scalare
    Customer

    Yes, of course, but if you have aa long list of procedures that could be needed to call, you end up with a very ugly and long if-elseif block, and if you have to add procedures at some point, you also need to edit the if-elseif block. If you could call the desired procedure by just using a variable name, things would be much easier and clean.
    Think of the procedure call puzzle, but where it accepts a text literal, or a variable.

    #19005
    scalare
    Customer

    Parameters for the procedures could also be dynamic. So, for example, if a procedure accepts 3 parameters, but another one accepts 5 parameters, we could just pass a list that we setup before the dynamic call.

    #19009

    Thanks for clarification. I agree that feature might be useful. We’ll consider it!

    Chief 3D Verger | LinkedIn | Twitter

    #19012
    scalare
    Customer

    Thank you, Yuri! :)

    #19026
    jem
    Customer

    This is an interesting feature request, but I was wondering if I could make this work today in 2.14? We could write a simple dispatching function in the ExternalInterface. It would take two arguments, the name of the function to be called and the arguments to pass on to that function. It would look something like this:

    	app.ExternalInterface.procedureCaller = function(procName, argsString) {
    		app.ExternalInterface[procName](JSON.parse(argsString));
        }

    For example, you could call it like this:
    app.ExternalInterface.procedureCaller("myProcedure1","{'color':'red', 'shape':'sphere'}");

    …but this does not work for ordinary procedure puzzles because their code is inside a closure and it is not accessible. However, this does work well for the “when called from JS as..” puzzle because those functions are published to the ExternalInterface.

    I can use this technique if I make a wrapper for each of my procedure puzzles. The wrapper is a “when called from JS as..” puzzle and it calls the procedure puzzle (see screenshot). This is a little ugly, but it does work. If there is a way to access the ordinary procedure puzzles from the ExternalInterface we could avoid this two-step.

    …and I used a JSON string argument to deal with the variable quantity of arguments that scalare mentioned in his post.

    Jeremy Wernick

    #19053

    Thanks for further clarification and the examples. I’ve created a task in our dev tracker so that we can proceed with it.

    Chief 3D Verger | LinkedIn | Twitter

    #19058
    scalare
    Customer

    Excellent Yuri, thank you! And thank you, jem. Your suggestion gave us an idea that we will test and see if we can make it work with the rest of what we’ve developed.

    #19085
    GLiFTeK
    Customer

    Hi,
    Something like this is possible now with logic puzzles. Is it what you’re looking for?

    would this be used in a Time “every frame do” puzzle or a Loops “repeat while” puzzle so that the if then is “waiting” for the “procedure” variable to change to something acceptable?

    #19086

    would this be used in a Time “every frame do” puzzle or a Loops “repeat while” puzzle so that the if then is “waiting” for the “procedure” variable to change to something acceptable?

    Yes, you can possibly use that if-else structure inside every frame puzzle, because it is asynchronous. However, this would likely produce an infinite loop with repeat while, which is not.

    Chief 3D Verger | LinkedIn | Twitter

    #19649

    In 2.15, we made it possible to call procedure puzzles directly from JavaScript. Let us know how it works for you!

    Chief 3D Verger | LinkedIn | Twitter

    #19650
    scalare
    Customer

    That’s great, Yuri, thank you! How do we have to call them? Any examples? And how do we pass parameters?

    #19655

    See the example provided with the release notes!

    Chief 3D Verger | LinkedIn | Twitter

    #19658
    scalare
    Customer

    Excellent, thank you!

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