[SOLVED] How do I make a hotbar switch?

Ok, here is a example of what you are saying.
Code on:


(Look bottom right)

Code off:


(Look bottom right)

no, should i have the script disable the object, Not vice versa

No or else the script won’t work.

so i disable the script on the item?

No. Your making me get a headache :sweat_smile:

im sorry, im very new, before i started this i’ve NEVER coded before

I think I’m giving everyone headaches :sweat_smile: lol

1 last question, i’ve been working on the hotbar switch, and i ran into a problem.
i have my flashlight out and i can still shoot.

If you don’t tell the shooting part of your code that the player is using the flashlight and not the pistol, the shooting part of your code will still do is job. You have to add an if statement to check if the pistol is enabled. Below an example. Be aware that the code I show you is just to give you an idea. The code is not optimized.

if (this.app.root.findByName(ā€œPistolā€).enabled === true) {
   // shooting code 
}

can i try it?

Yes that’s why I sent it of course. :upside_down_face:

it shows an error and now it doesn’t shoot, not even for the gun

this the code

if (this.app.root.findByName('Pistol').enabled === true) {
   // shooting code 
Movement.prototype.onMouseDown = function(event) {
    if (event.button === pc.MOUSEBUTTON_LEFT) {
        // shoot
        if (this.rounds !== 0) {
            var bullet = this.app.root.findByName('Bullet').clone();
            this.app.root.addChild(bullet);
            bullet.reparent(this.app.root);
            bullet.setPosition(this.app.root.findByName('Bullet').getPosition());
            bullet.setRotation(this.app.root.findByName('Bullet').getRotation());
            bullet.enabled = true;
            console.log(bullet);
            // update magazine
            this.rounds = this.rounds - 1;
        }
    }
};
}

Because you placed the code outside the function.

// Function start (recognizable by the script name)
Movement.prototype.onMouseDown = function(event) {

// Function end
};

wait im confused, do i do this

// Function start (recognizable by the script name)
Movement.prototype.onMouseDown = function(event) {
if (this.app.root.findByName('Pistol').enabled === true) {
   // shooting code 
Movement.prototype.onMouseDown = function(event) {
    if (event.button === pc.MOUSEBUTTON_LEFT) {
        // shoot
        if (this.rounds !== 0) {
            var bullet = this.app.root.findByName('Bullet').clone();
            this.app.root.addChild(bullet);
            bullet.reparent(this.app.root);
            bullet.setPosition(this.app.root.findByName('Bullet').getPosition());
            bullet.setRotation(this.app.root.findByName('Bullet').getRotation());
            bullet.enabled = true;
            console.log(bullet);
            // update magazine
            this.rounds = this.rounds - 1;
        }
    }
};
}
// Function end
};

No of course not. Just replace the if statement inside the fuction.

// Function start (recognizable by the script name)
Movement.prototype.onMouseDown = function(event) {
    if (this.app.root.findByName('Pistol').enabled === true) {
       // shooting code 
        if (event.button === pc.MOUSEBUTTON_LEFT) {
            // shoot
            if (this.rounds !== 0) {
                var bullet = this.app.root.findByName('Bullet').clone();
                this.app.root.addChild(bullet);
                bullet.reparent(this.app.root);
                bullet.setPosition(this.app.root.findByName('Bullet').getPosition());
                bullet.setRotation(this.app.root.findByName('Bullet').getRotation());
                bullet.enabled = true;
                console.log(bullet);
                // update magazine
                this.rounds = this.rounds - 1;
            }
        }
    }
// Function end
};

what is intense?

do i just copy it?

Yes @thebosser24, what else?

ok

OMGOSH, It works, @Albertos @Gabriel_Dobrzynski @Leonidas @yaustar
Your all the best, kudos to you for all the help you gave me

2 Likes