Jump to content

getting error while using nativui with functions in javascript and passing a argument


Bumsnudel

Recommended Posts

hey guys

i wrote a .js file within in i tried to develop some menus for vehicle handling etc.

it basically opens a menu via nativui by a key bind.

everything works fine until i started to sum up a few things for a better overview in the code.

my last change was to create functions where i put the same code in.

function veh_menu_codriver() {
    const ui_veh_main_temp = new Menu("Fahrzeugmenü", "Beifahrer:", new Point(25, 25));

    mp.gui.cursor.visible = false;
    mp.gui.chat.show(false);

    ui_veh_main_temp.AddItem(new UIMenuItem("Anschnallen", "Schnallt dich an."));

    ui_veh_main_temp.AddItem(new UIMenuItem("Kofferraum öffnen", "Schnallt dich an."));

    ui_veh_main_temp.AddItem(new UIMenuItem("Animationen", "Schnallt dich an."));

    ui_veh_main_temp.AddItem(new UIMenuItem("Fahrzeuginformationen", "Zeigt Fahrzeuginformationen an."));

    ui_veh_main_temp.AddItem(new UIMenuItem("Schließen", "Schließt das Menü."));

    ui_veh_main_temp.ItemSelect.on((item, index)  => {
        switch (item.Text) {
            case "Anschnallen":
                mp.players.local.setConfigFlag(32, false);
                mp.game.graphics.notify(`Du hast dich ~g~angeschnallt~w~.`);
                ui_veh_main_temp.Close();
                mp.gui.chat.show(true);
                break;
            case "Kofferraum öffnen":
                break;
            case "Animationen":
                veh_menu_submenu_animationen(ui_veh_main_temp);
                break;
            case "Fahrzeuginformationen":
                veh_menu_submenu_info(ui_veh_main_temp);
                break;
            case "Schließen":
                ui_veh_main_temp.Close();
                mp.gui.chat.show(true);
                break;
            default:
                ui_veh_main_temp.Close();
                mp.gui.chat.show(true);
                break;
        }
    });
    ui_veh_main_temp.Open();
}

in the events section (itemselect.on) i distinguish between the items and try to call another functions which should open another menu.

function veh_menu_submenu_info(last_opened_menu) {
    arguments[0].Close();
    //last_opened_menu.Close();
    const veh_menu_info = new Menu("Fahrzeugmenü", "Fahrzeuginformationen:", new Point(25, 25));

    veh_menu_info.AddItem(new UIMenuItem("Schließen", "Schließt das Menü."));

    veh_menu_info.ItemSelect.on((item, index)  => {
        switch (item.Text) {
            case "Schließen":
                veh_menu_info.Close();
                arguments[0].Open();
        }
    });
}

in addition i had to pass a variable to the function which is the const from the specified menu (which was opened before)

so i want to close the menu before and open the new one.

furthermore there is a event (Itemselect.on) to close the new menu and open the one before.

so i passed the const an took it later from the first argument of the function.

this and the commented line underneath result in this error when i triggered the key bind and it gets loaded:

https://ibb.co/0qxk1tp

i think the problem is caused by the passing arg but i dont know how to fix this.

so maybe somebody can help me?

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...