[SOLVED] Declare array variable

Is this code correct? CharSelect.attributes.add(‘langImg’, {type: ‘asset’, assetType: ‘image’ ,array: true});

Hi @ayrin,

So, there isn’t any assetType called image, that should be texture. But still I think the array: true property seems to be broken right for asset attributes.

@will @vaios any idea why? From what I remember array: true used to work specifically for asset attributes.

I have got an error, is this line ok or deprecated? var language = this.app.assets.get(this.dbase[0]).resource;

It seems to be, what kind of error are you getting?

Can you share a bit more code on how you are preparing/loading this?

Sure @Leonidas

CharSelect.attributes.add('dbase', {type: 'asset', assetType: 'json' ,array: true});
CharSelect.attributes.add('langImg', {type: 'asset', assetType: 'texture' ,array: true});

This load the assets and the following use them

var language = this.app.assets.get(this.dbase[0]).resource;
if (this.lang==='en') {
                language =this.app.assets.get(this.dbase[0]).resource;
            if (this.lang==='it') {
                language =this.app.assets.get(this.dbase[1]).resource;
            if (this.lang==='de') {
                language =this.app.assets.get(this.dbase[2]).resource;

and i get this.app.assets.get(…) is undefined

1 Like

Did you check if the this.dbase is indeed defined and contains the assets? Not sure if array: true works right now.

Also the attribute would make sure to return the the assets, you don’t have to do this.app.assets.get() etc.

So for a single asset this will work:

CharSelect.attributes.add('dbase', {type: 'asset', assetType: 'json' });

By the way if you are using the Playcanvas UI/Text elements there is now native support for localization:


No, haven’t implemented the localization so far, will add it since i’m updating the game to new scripts…it will be hell.

1 Like

So also for textures i can’t use an array?? :frowning:
and this is no valid anymore?


I think right now it doesn’t work using the array: true attribute property.

What you can easily do instead is select your assets in the assets panel and add a tag (e.g. language).

Then in your code you can get an array with all of them like this:

var languageAssets = this.app.assets.findByTag('language');

I solved that part now, now have another error using the language :frowning:

@Leonidas i have a variable that loose the value in this code, can you understand why?
Variable is charSheetWidth (but not just that)

What do you mean charSheetWidth is loose? When I run your project I see these two mistakes:

a is undefined
this.entity.script.CharSelect is undefined

They are hard to debug, you have tons of code in there!

I have just this 2 errors visible (for now) so i want solve the first at line 95 in buttons.js that error is due to the variable this.charSheetWidth that is undefined but it’s set inside initialize function at line 6. I see no reason to get loose unless there is a bigger error somewhere.

Not sure about that, but I can see bigger errors elsewhere. You seem to be losing the right context when calling Playcanvas related script methods/properties.

Like this, this.app seems to be undefined in that raphael callback, it should be self.app:

In general, use console.log(this) or console.log(self) when you get errors like that to see if you are targeting the correct context.

I see, i have sected a break point at line 6, it doesn’t run that line :open_mouth: It skips all the initialize code

1 Like

I think i will need more time than i thought to master the new scripts…i don’t get why the initialize function is executed after the line 102 (that is executed 2 times). I guess the logic is a bit different from old scripts. sigh!!

this.entity doesn’t work anymore on new scripts?

No, it works, it’s available in all script methods, study the tutorials and how they use it:


1 Like

Thanks @Leonidas , solved the issues for now

1 Like