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.

How to reference a Verge 3d varible in a Javascript Code Puzzle

Home Forums General Questions How to reference a Verge 3d varible in a Javascript Code Puzzle

Viewing 15 posts - 1 through 15 (of 32 total)
  • Author
    Posts
  • #77731
    blippypixel
    Customer

    Hi there

    How do you reference a Verge3d variable in Javascript code?
    Thanks!

    #77737

    Hi blippypixel,

    Good question! You cannot access puzzles’ variables directly, by you can use a procedure this way:

    v3d.puzzles.procedures['getVar']('myVar1'); // 'Hello'
    v3d.puzzles.procedures['getVar']('myVar2'); // 'Verge3D'
    

    Chief 3D Verger | LinkedIn | X

    #77741
    blippypixel
    Customer

    Thank you Yuri! :good:

    #77745
    blippypixel
    Customer

    Sorry Yuri. I had a go at this. I’m a bit confused.
    The procedure above – I can’t see how you can add one like your example.
    to getVar with: varname

    I can’t see with: varname in the procedure puzzle.
    Also where is the ‘variable value by name’ please? I know they are colour coded but I can’t find it either. Sorry!

    Maybe it would be useful if Verge had a search function so the user could search for a puzzle by name. Thanks!

    #77763
    blippypixel
    Customer

    Sorry I just saw you had attached the puzzle to this so I will try that. Apologies

    #77764
    blippypixel
    Customer

    Sorry I thought your webp attachment was the code or the project not a screenshot! I am still trying to work this out….

    #77772
    Brameister
    Participant

    Hi there

    How do you reference a Verge3d variable in Javascript code?
    Thanks!

    VARS[‘variableName’]

    Not sure if I understood you correctly, but does that help?

    #77793
    blippypixel
    Customer

    Thank you. It’s kind of you to try to help.
    Is that what you write in Javascript? VARS
    If anyone can point me to the page with the documentation or an example it would be great.
    Sorry I am really struggling with this simple thing!

    #82948
    c4cc
    Customer

    v3d.puzzles.procedures['getVar']('myVar1'); // 'Hello'
    v3d.puzzles.procedures['getVar']('myVar2'); // 'Verge3D'
    

    Let’s say myVar1 and myVar2 were numbers and not text, would the code be written like this:

    `document.getElementById(“”).contentWindow.v3d.puzzles.procedures[‘getVar’](‘myVar1’) = 0.07;

    I’m trying to write down my puzzle variable numbers as code:

    puzzles:

    javascript code:

    Basically, I’m trying to increase puzzle number values when javascript triggers fullscreen, and back to default value when javascript exits fullscreen.

    • This reply was modified 2 days, 22 hours ago by c4cc.
    • This reply was modified 2 days, 22 hours ago by c4cc.
    • This reply was modified 2 days, 22 hours ago by c4cc.
    • This reply was modified 2 days, 22 hours ago by c4cc.
    • This reply was modified 2 days, 21 hours ago by c4cc.
    #82955
    bigmike814
    Customer

    No, you are just referencing the set value not setting it. If you want to be able to reference or set values outside the v3d environment use the window and set it as an object.

    Open your console and type window and hit enter. It will give you an object with a bunch of other object. You want to set your object to the window if you want to use it cross platform.

    I’d recommend naming objects, functions and setters (variables) using camel case so you can keep your internal window objects separate.

    Now you can reference the value using window.PetraBasicMoveRange and if you want to change the value with an external function you can window.PetraBasicMoveRange = 12;
    and it will set the value.

    #82960
    bigmike814
    Customer

    here are some more screenshots. You’re already referencing the window, but it you want to set values externally, the window is the best way. Also, if you get in the habit of using objects globally, your life will be much simpler.

    #82963
    bigmike814
    Customer

    you can also set key value pairs in the object and then call them

    window.PetraBasicMoveRange = {
    min: 5,
    max: 15,
    unit: “feet”
    };

    console.log(window.PetraBasicMoveRange.min) = 5

    console.log(window.PetraBasicMoveRange.max) = 15

    console.log(window.PetraBasicMoveRange.unit) = feet

    #82964
    c4cc
    Customer

    first 2 steps worked

    but when I tried to do window.PetraBasicMoveRange = 12;, nothing happened

    document.getElementById("gamescreen").contentWindow.v3d.puzzles.procedures['getfsr']('PetraBasicMoveRange').window.PetraBasicMoveRange = "0.07";

    Where am I getting it wrong? Thanks.

    #83029
    c4cc
    Customer

    Open your console and type window and hit enter. It will give you an object with a bunch of other object. You want to set your object to the window if you want to use it cross platform.

    Now you can reference the value using window.PetraBasicMoveRange and if you want to change the value with an external function you can window.PetraBasicMoveRange = 12;
    and it will set the value.

    Also, do I do this in Visual Studio Code, or the earlier console where I typed in “window”?

    #83033
    bigmike814
    Customer

    Do it in the bottom of your console where you would get your console logs. You can even call your functions in there to test if you have them right before putting them in code.

    If you’re using an iframe you have to set it in the contentWindow

    document.getElementById("gamescreen").contentWindow.PetraBasicMoveRange = "0.07";

    you set the
    let elem = document.getElementById("gamescreen") just use that. elem.contentWindow.PetraBasicMoveRange = "0.07"

    think of the name before each period as the address like breadcrumbs.

    • This reply was modified 2 days ago by bigmike814.
Viewing 15 posts - 1 through 15 (of 32 total)
  • You must be logged in to reply to this topic.