ThymonA/menuv

<menu>:Close not working

MadsLeander opened this issue · 7 comments

Hello! To start off I would like to say that the resource is really awesome, but quite recently I came over a problem with the menu:Close() function.

When I trigger it (see code below) it returns this error:

error

It's fired when you select the button as seen here:

menu_button_unemployed:On('select', function(menu)
	if job ~= "unemployed" then
		menu:Close()
		TriggerServerEvent('jobs:newjob', GetPlayerServerId(PlayerId()), 'unemployed')
		exports.mythic_notify:DoHudText('success', 'You are now unemployed!')
	else
		exports.mythic_notify:DoHudText('error', 'You are already unemployed!')
	end
end)

Any clues on what going on? I have the newest release (v1.4).
I've also tried to reinstall MenuV just to be sure.

Thanks in advance.

Edit: in the picture, it says 'CloseMenu', which is not the one that I use in the code above, however the menu:Close() function returns the same error when used instead. AKA it's the same I only attached the wrong picture.

error2

menu_button_unemployed:On('select', function(menu)

function(menu) isn't right, because it isn't returning the menu but the selected item.
https://menuv.fivem.io/api/#ButtonItem#event:select

What your trying to do can't work. You should do it as follow:

menu_button_unemployed:On('select', function(item)
	if job ~= "unemployed" then
	        local menu = item:GetParentMenu()
		menu:Close()
		TriggerServerEvent('jobs:newjob', GetPlayerServerId(PlayerId()), 'unemployed')
		exports.mythic_notify:DoHudText('success', 'You are now unemployed!')
	else
		exports.mythic_notify:DoHudText('error', 'You are already unemployed!')
	end
end)

Thanks for the response! I did as you showed above (I copied pasted it), however, it didn't close the menu visually. It only "disabled" it's functionality (the buttons no longer have any effect). Do you know why that could be? Sorry if I'm just asking stupid questions.

Here's a picture:
menuv3

You can use MenuV:CloseAll() to close all the menus.

menu_button_unemployed:On('select', function(item)
	if job ~= "unemployed" then
	        local menu = item:GetParentMenu()
		MenuV:CloseAll()
		TriggerServerEvent('jobs:newjob', GetPlayerServerId(PlayerId()), 'unemployed')
		exports.mythic_notify:DoHudText('success', 'You are now unemployed!')
	else
		exports.mythic_notify:DoHudText('error', 'You are already unemployed!')
	end
end)

You can do what Dope said and use CloseAll instead.

Alright, seems to work, thanks a lot for the help! I appreciate it!

@ThymonA

MenuV:CloseMenu(menu2, function()
	print('Menu closed :(')
end)

This does print the output but the menu stays open. I cannot move to one menu to other in single script due to this.