Home › Forums › Programming › calling procedures from js
- This topic has 6 replies, 3 voices, and was last updated 4 years, 9 months ago by GLiFTeK.
-
AuthorPosts
-
2020-02-11 at 11:34 pm #23475GLiFTeKCustomer
hi
i’m having an issue where v3d.puzzles is undefined.
i’m calling procedures from a js script section of my index.html file.i know v3d.js has to be loaded for it to work.
i have my v3d.js and my app’s js file all set working.
in order far before the script line.
i’ve used jquery
$(document).ready(function()
before to make sure the page is all loaded before the function is run, but this isn’t working.even in the console, it says it after verge loads.
does this HAVE to be within my app’s js file?
if so, i need the puzzle procedure to run WITHIN a certain html DIV, and i don’t know how to specify within the puzzles or within my app’s js file. this is why i’m trying to have it activate in the html script section where it is.
advice?
thanks
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-02-12 at 1:36 am #23476GLiFTeKCustomerI’m trying the query selector instead of “container”..
tried.. container.div1.div2where div1/2 are id’s of the nested divs.
i want the puzzles to add elements into div2Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-02-12 at 2:38 am #23478GLiFTeKCustomerok on a whim i tried using css selector syntax.
worked.so in the query selector i had to use # for id before it’s name
or . (period) before a class.
this should be in the documentation i think.
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-02-12 at 6:31 am #23484Yuri KovelenovStaff2020-02-12 at 6:50 am #23487GLiFTeKCustomerAgreed. Anyway, I’m glad you worked it out!
well. no that was my work around for not being able to call the v3d.puzzles.procedure line.
well.. a work around for a work around hah..i still want to know that though.. what needs to be done to have that work?
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-02-12 at 8:40 am #23488Ivan LyubovnikovStaffHi GlifTek,
If you need to execute procedures from puzzles you surely have to wait till the page is loaded and the procedures are available. But it’s a bit more complicated than just to detect page loading with
$(document).ready
.
This is because your app’s js file itself waits until the page is fully loaded and after that it schedules loading of the visual_logic.js file which contains the code generated from puzzles. And only after it’s loaded you can call procedures from v3d.puzzles. So, basically you need to detect a moment that is a bit later than when$(document).ready
is triggered.The easiest way to do that is to add your code inside the app’s js file, for example in the runCode() function, but if you want to use an approach similar to
$(document).ready
then you can create a custom event dispatcher and listen to it:<script> v3d._customEvents = new v3d.EventDispatcher(); v3d._customEvents.addEventListener('onload', function(event) { console.log(v3d.puzzles); }); </script>
– so instead of
$(document).ready
you usev3d._customEvents.addEventListener('onload', ...
wherever you need itTo make it work you also need to manually dispatch this event at the moment the app is loaded (and puzzle procedures are available), for example in the app’s js file in the runCode() function:
function runCode(app) { if (v3d._customEvents) { v3d._customEvents.dispatchEvent({ type: 'onload' }); } }
Co-founder and lead developer at Soft8Soft.
2020-02-12 at 5:41 pm #23511GLiFTeKCustomerGreat Ivan!
Thanks a lot!Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature! -
AuthorPosts
- You must be logged in to reply to this topic.