Page 1 of 1
dojo: where's thé object created?
Posted: 29 January 2024, 15:44
by Fred504
Hello
In the coinche.js example, I see the use or dojo.
I see 'this' but canne see where it Comes from
- where the object is created
- what's it's class
Thanks for your help.
Re: dojo: where's thé object created?
Posted: 30 January 2024, 00:42
by robinzig
There's no "class" here, simply because the BGA framework has been around for way longer than JS has had the "class" keyword. But it's a similar mechanism - basically that big object you define in the .js file of your game, with all those functions/methods in it, and properties that you access as this.whatever, is a singleton instance of the "class" you're defining there.
That "class" also "inherits" from one that's defined in the BGA framework, which allows you to call other methods and even override them (one example you might have seen in the docs is overriding the format_string_recursive method, which can allow you to put "pretty" game images in the log - this also shows you the syntax you need to call the "inherited" method). Unfortunately I'm not aware of anywhere in the docs where all its methods and properties are defined (but since this is all client-side code you can easily find the ly_studio.js file when running your game on Studio, and look inside it - you used to have to run it through an un-minifier to make any sense of it, and cope with the 1-character variable names even then, but I seem to recalll it's no longer minified on Studio, which is nice for debugging

).
Note that dojo is rather separate from this question - it's just a (very old and rather outdated) JS library that the BGA framework makes use of internally, that you are free to use or not in your own code (most devs now don't bother as vanilla JS is so much better than it was 10-15 years ago and browser incompatibilities, although still existing, are much less bad than they were). That has no bearing on the object that "this" refers to in your JS code. (Dojo is what provides the particular "fake class" mechanism that BGA happens to use but that's really only incidental.)