If item == newitem not working in NativeUILua

It simply doesn’t work, I’m trying to do this:

        menu.OnItemSelect = function(sender, item, index)
			if item == p_msg then
				DisplayOnscreenKeyboard(1, "FMMC_MPM_NA", "", "", "", "", "", 30)
    			while (UpdateOnscreenKeyboard() == 0) do
    			    DisableAllControlActions(0);
    			    Wait(0);
    			end
    			if (GetOnscreenKeyboardResult()) then
    			    local result = GetOnscreenKeyboardResult()
					print(GetOnscreenKeyboardResult())
    			end
			end
		end

But rather, nothing shows up and it doesn’t detect the item being pressed. Please help!

In line 2 of your code add print(tostring(item)) (before the if statement) and do the same for variable p_msg. It will tell you exactly what the items is (or if even exists). Let me know what is the outcome.

I got this:
image

Ok, so we see that both variables are actually real - they exist. What you might want to do is to compare a given property of these objects, not the whole objects. Let’s try with name property. Please try changing your if statement to if (item and item.name) == (p_msg and p_msg.name) then .... This way you are guarding the statement from item nad p_msg not existing + you compare the names of the items, instead of the objects themselves.

NOTE: there might not be name property on these objects. Also you might want to check if there is any other property that would be unique (like item code).

1 Like

That worked, thank you so much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.