[SOLVED] Car selection issue with ui element

I try to convert from html buttons to screen&element UI
the index is changing but the cars are not switching

    initialize() {

        let index = 0;

        const self = this;
        const onBtnLeft = function(){
            --index;
            console.log('left', index);
            self.toggleCar(index);

        };
        const onBtnRight = function(){
            ++index;
            console.log('right', index);

            self.toggleCar(index);

        };
       
        this.btnLeft.element.on('click', onBtnLeft);
        this.btnRight.element.on('click', onBtnRight);


  }
   
    toggleCar(index){
        const showroom = this.entity.script.showroom;
        showroom.hideAll();
        const lastIndex = showroom.cars.length - 1;
        const indexExceedsArray = index < 0 || index > lastIndex;

        if(indexExceedsArray){
            return;
        }
        showroom.showOne(index);

    }

Hi @grzesiekmq,

Can you verify that this method is being called?

1 Like

yes it is called I console logged in toggleCar()

Then I don’t think the code you posted above is where your issue lies.

Try debugging your toggleCar() method and see why it doesn’t switch the car element/model based on the index you pass.

If you keep having issues, try posting a sample project that reproduces the issue to take a look.

2 Likes

ok I found in showroom.js
this.cars = this.entity.findByTag('car');
I have attached the showroom.js to screen element
so when this.entity is screen element then can’t find with tag car because cars are not there
then the cars not toggling

I suppose you solved the problem by using this.cars = this.app.root.findByTag('car'); or something like that?

2 Likes

yes

1 Like