Skip to content

Functions Client ​

Reference of all the functions and methods of the menu module. To discover the possibilities of the menu step by step, start with the Menu page.

Constructor ​

Client jo.menu.create() ​

Create a new menu. If a menu with the same ID exists, it's replaced
Add the items with MenuClass:addItem(), then send the menu to the NUI with MenuClass:send()

TIP

All the options of a menu are illustrated in Menus.

Syntax ​

lua
jo.menu.create(id, data)

Parameters ​

id : string

Unique ID of the menu

data : table

The menu configuration

data.title : string - The big title of the menu. HTML is allowed
default: "Jump On" Optional

data.subtitle : string - The subtitle of the menu, displayed above the items. HTML is allowed
default: "" Optional

data.type : string - The type of menu: list or tile
default: "list" Optional

data.numberOnScreen : integer - list menu: number of items displayed before the scroll. Maximum 13
default: 8 Optional

data.numberOnLine : integer - tile menu: number of tiles per line
default: 4 Optional

data.numberLineOnScreen : integer - tile menu: number of lines displayed before the scroll
default: 6 Optional

data.image : string|table - An image displayed above the items: a URL or {url, width, height, radius, style} Optional

data.displayBackButton : boolean - Display the back arrow next to the subtitle, even without history
default: false Optional

data.hideBackground : boolean - Hide the dark background behind the menu
default: false Optional

data.price : number|table - The price displayed when the active item has no price. See Prices Optional

data.priceTitle : string - Replace the "Price" label of data.price Optional

data.distanceToClose : number - The menu closes itself when the player moves further than this distance
default: false Optional

data.translateTitle : boolean - Use title as a key of the translation strings
default: false Optional

data.translateSubtitle : boolean - Use subtitle as a key of the translation strings
default: false Optional

data.onBeforeEnter : function - Fired before the menu is displayed. The NUI waits for the end of the function Optional

data.onEnter : function - Fired when the menu becomes the current menu Optional

data.onBack : function - Fired when Backspace or Escape is pressed Optional

data.onExit : function - Fired when the menu is no longer the current menu Optional

data.onChange : function - Fired when the active item or a slider changes in the menu Optional

data.onTick : function - Fired every frame while the menu is the current menu Optional

Return Value ​

Type : MenuClass

The new menu

Example ​

lua
local menu = jo.menu.create("tailor", {
  title = "Tailor",
  subtitle = "Clothes",
  type = "list",
  numberOnScreen = 12,
  onEnter = function(currentData)
    print("Enter the tailor")
  end,
  onBack = function(currentData)
    jo.menu.show(false)
  end,
})

menu:addItem({ title = "Hats", icon = "hats", child = "hats" })
menu:addItem({ title = "Coats", icon = "coats", child = "coats" })
menu:send()

menu:use()
jo.menu.show(true)
Preview

Client jo.menu.createIfNotExist() ​

Create a new menu, only if no menu exists with this ID
Returns two values: the menu (the new one or the existing one) and true if the menu was created

Syntax ​

lua
jo.menu.createIfNotExist(id, data)

Parameters ​

id : string

Unique ID of the menu

data : table

The menu configuration. See jo.menu.create()

Return Value ​

Type : MenuClass

The menu

Example ​

lua
local menu, created = jo.menu.createIfNotExist("tailor", { title = "Tailor" })
if created then
  menu:addItem({ title = "Stetson" })
  menu:send()
end
menu:use()
jo.menu.show(true)

Add an item to the menu. Call MenuClass:send() to send the menu to the NUI

TIP

All the options of an item are illustrated in Items, the sliders in Sliders and the statistics in Statistics.

Syntax ​

lua
MenuClass:addItem(index, item)

Parameters ​

index : integer|table

The position of the item in the menu, or the item itself to add it at the end

item : table Optional

The item to add, when index is a position

item.title : string - The item label. HTML is allowed

item.subtitle : string - A second line displayed under the title Optional

item.description : string - The text displayed in the description area, under the list. HTML is allowed Optional

item.footer : string - The text displayed at the bottom of the menu. HTML is allowed Optional

item.child : string - The ID of the menu opened when the item is clicked
default: false Optional

item.visible : boolean - If false, the item is not displayed
default: true Optional

item.disabled : boolean - Grey out the item: it can't be clicked and its sliders are hidden
default: false Optional

item.data : table - Free storage for your own data, available in the callbacks with currentData.item.data Optional

item.icon : string - The icon on the left of the item: a filename of nui/menu/assets/images/icons (without .png) or a full image URL Optional

item.iconClass : string - CSS classes applied to the icon, like fgold or bw. See CSS classes Optional

item.iconSize : string - "small" to reduce the size of the icon
default: "normal" Optional

item.iconRight : string - An icon displayed on the right of the item. In a tile menu, it's displayed in the bottom right corner of the tile Optional

item.prefix : string - A small icon displayed before the title Optional

item.textRight : string - A text displayed on the right of the item Optional

item.textRightClass : string - CSS classes applied to textRight, like tiny Optional

item.image : string|table - An image displayed in the description area: a URL or {url, width, height, radius, style} Optional

item.color : string|table - The CSS color of the title, or a table {title, background, accent, icon}. See Colors Optional

item.price : number|table - The price displayed under the description. See Prices
default: false Optional

item.priceTitle : string - Replace the "Price" label above the price Optional

item.priceRight : boolean|number|table - Display a price on the right of the item: true to display item.price, or a price value Optional

item.statistics : table - The list of statistics displayed in the description area. See Statistics Optional

item.sliders : table - The list of sliders of the item. See Sliders Optional

item.previewPalette : boolean - Display a square with the current color of the sliders on the right of the item
default: false Optional

item.quantity : number - In a tile menu, a number displayed in a circle in the top right corner of the tile Optional

item.quantityCircleClass : string - CSS classes applied to the quantity circle, like fgold Optional

item.quality : integer - In a tile menu, a quality from 1 to 3 displayed with stars Optional

item.qualityClass : string - CSS classes applied to the quality stars Optional

item.stars : table - In a tile menu, a row of stars: {current, total} Optional

item.starsClass : string - CSS classes applied to the row of stars Optional

item.tilePadding : number|string - In a tile menu, the space between the image and the edge of the tile: a number in vh, or a CSS length. 0 brings the image to the edge
default: 1.2 Optional

item.translate : boolean - Use title as a key of the translation strings. See jo.menu.updateLang()
default: false Optional

item.translateDescription : boolean - Use description as a key of the translation strings
default: false Optional

item.translateTextRight : boolean - Use textRight as a key of the translation strings
default: false Optional

item.bufferOnChange : boolean - Wait a few milliseconds between two onChange events of fast slider moves. false fires them on the next frame
default: true Optional

item.onActive : function - Fired when the item becomes the active item Optional

item.onClick : function - Fired when the item is clicked or Enter is pressed Optional

item.onChange : function - Fired when a slider of the item changes Optional

item.onExit : function - Fired when the item is no longer the active item Optional

item.onTick : function - Fired every frame while the item is active Optional

Return Value ​

Type : MenuItemClass

The added item

Example ​

lua
local menu = jo.menu.create("tailor", { title = "Tailor", subtitle = "Hats" })

-- Add an item at the end of the menu
local stetson = menu:addItem({
  title = "Stetson",
  icon = "hats",
  description = "A wide brim hat made of felt.",
  price = { money = 12.5 },
  data = { hash = `HAT_STETSON` },
  sliders = {
    { title = "Variation", values = { "Brown", "Black", "Grey" } },
  },
  onClick = function(currentData)
    print("Buy", currentData.item.data.hash)
  end,
})

-- Add an item at the first position
menu:addItem(1, { title = "Remove the hat" })

menu:send()
Preview

Delete an item of the menu and update the index of the next items. Call MenuClass:push() to send the changes to the NUI

Syntax ​

lua
MenuClass:deleteItem(index)

Parameters ​

index : integer

The index of the item to delete

Example ​

lua
local menu = jo.menu.get("tailor")
menu:deleteItem(2)
menu:push()

Delete a property of the menu or of one of its items. Call MenuClass:push() to send the changes to the NUI
{"items", index} deletes the item, like MenuClass:deleteItem()

Syntax ​

lua
MenuClass:deleteValue(keys)

Parameters ​

keys : string|table

The property name, or the path to a nested property like {"items", 2, "price"}

Example ​

lua
local menu = jo.menu.get("tailor")
-- Remove the price of the 2nd item
menu:deleteValue({ "items", 2, "price" })
menu:push()

Send to the NUI the changes made with updateValue(), deleteValue() and deleteItem()

Syntax ​

lua
MenuClass:push()

Example ​

lua
local menu = jo.menu.get("tailor")
menu:updateValue("subtitle", "Hats (2)")
menu:updateValue({ "items", 1, "textRight" }, "Owned")
menu:deleteValue({ "items", 1, "price" })
-- Send the 3 changes to the NUI
menu:push()
Preview

Send the whole menu to the NUI again, without changing the active item
Use it after big changes, like items added or sorted after MenuClass:send()
If the menu is the current menu, onExit and onActive of the active item are fired again

Syntax ​

lua
MenuClass:refresh()

Example ​

lua
local menu = jo.menu.get("tailor")
menu:addItem({ title = "Top hat", icon = "hats" })
menu:sort()
-- Send the whole menu again, the cursor stays on the same item
menu:refresh()

DEPRECATED

since v2.4.0. Use MenuClass:deleteItem() instead

Remove an item from the menu, in Lua only

Syntax ​

lua
MenuClass:removeItem(index)

Parameters ​

index : integer

The index of the item to remove

Example ​

lua
local menu = jo.menu.get("tailor")
-- Deprecated: use deleteItem() then push()
menu:deleteItem(2)
menu:push()

Move the cursor of the menu back to the first item

Syntax ​

lua
MenuClass:reset()

Example ​

lua
local menu = jo.menu.get("tailor")
menu:reset()

Send the menu to the NUI. Call it once the items are added
If the menu has already been sent, it's refreshed (see MenuClass:refresh())

Syntax ​

lua
MenuClass:send()

Example ​

lua
local menu = jo.menu.create("tailor", { title = "Tailor" })
menu:addItem({ title = "Stetson" })
menu:addItem({ title = "Bowler" })
-- Send the menu once all the items are added
menu:send()

Move the cursor to an item

Syntax ​

lua
MenuClass:setCurrentIndex(index)

Parameters ​

index : integer

The index of the item

Example ​

lua
local menu = jo.menu.get("tailor")
-- Move the cursor to the 3rd item
menu:setCurrentIndex(3)

Sort the items alphabetically by title
Call MenuClass:refresh() (or MenuClass:send() if the menu has never been sent) to display the new order

WARNING

sort() doesn't update the NUI: call MenuClass:refresh() after it, or MenuClass:send() if the menu has never been sent.

Syntax ​

lua
MenuClass:sort(first, last)

Parameters ​

first : integer Optional

The position of the first item to sort
default: 1

last : integer Optional

The position of the last item to sort
default: the last item

Example ​

lua
local menu = jo.menu.create("tailor", { title = "Tailor" })
menu:addItem({ title = "Remove the hat" })
menu:addItem({ title = "Stetson" })
menu:addItem({ title = "Bowler" })
menu:addItem({ title = "Flat cap" })
-- Sort the items from the 2nd one: "Remove the hat" stays first
menu:sort(2)
menu:send()

DEPRECATED

since v2.3.0. Use MenuClass:updateValue() or MenuItem:updateValue() then MenuClass:push() instead

Overwrite a property of an item. The NUI is not updated

Syntax ​

lua
MenuClass:updateItem(index, key, value)

Parameters ​

index : integer

The index of the item to update

key : string

The property name to update

value : any

The new value for the property

Example ​

lua
local menu = jo.menu.get("tailor")
-- Deprecated: use updateValue() then push()
menu:updateValue({ "items", 2, "title" }, "Bowler hat")
menu:push()

Update a property of the menu or of one of its items. Call MenuClass:push() to send the changes to the NUI
price and priceRight values are formatted automatically

Syntax ​

lua
MenuClass:updateValue(keys, value)

Parameters ​

keys : string|table

The property name, or the path to a nested property like {"items", 2, "title"}

value : any

The new value

Return Value ​

Type : boolean

Always true

Example ​

lua
local menu = jo.menu.get("tailor")
-- A property of the menu
menu:updateValue("subtitle", "Hats (2)")
-- A property of an item
menu:updateValue({ "items", 2, "disabled" }, true)
-- A nested property
menu:updateValue({ "items", 1, "sliders", 1, "current" }, 3)
menu:push()

Set the menu as the current menu. Same as jo.menu.setCurrentMenu()

Syntax ​

lua
MenuClass:use(keepHistoric, resetMenu)

Parameters ​

keepHistoric : boolean Optional

Keep the previous menu in the history, to go back to it with Backspace
default: true

resetMenu : boolean Optional

Move the cursor back to the first item
default: true

Example ​

lua
local menu = jo.menu.get("tailor")
menu:use()
jo.menu.show(true)

Delete a property of the item. Call MenuClass:push() to send the changes to the NUI
Only works on an item returned by MenuClass:addItem()

Syntax ​

lua
MenuItemClass:deleteValue(keys)

Parameters ​

keys : string|table

The property name, or the path to a nested property like {"sliders", 2}

Example ​

lua
local menu = jo.menu.create("tailor", { title = "Tailor" })
local stetson = menu:addItem({ title = "Stetson", price = { money = 12.5 } })
menu:send()

-- Later
stetson:deleteValue("price")
menu:push()

Get the menu the item belongs to
Only works on an item returned by MenuClass:addItem()

Syntax ​

lua
MenuItemClass:getParentMenu()

Return Value ​

Type : MenuClass

The parent menu

Example ​

lua
local menu = jo.menu.create("tailor", { title = "Tailor" })
local stetson = menu:addItem({ title = "Stetson" })

local parent = stetson:getParentMenu()
print(parent.id) -- "tailor"

Update a property of the item. Call MenuClass:push() to send the changes to the NUI
Only works on an item returned by MenuClass:addItem()

Syntax ​

lua
MenuItemClass:updateValue(keys, value)

Parameters ​

keys : string|table

The property name, or the path to a nested property like {"sliders", 1, "current"}

value : any

The new value

Example ​

lua
local menu = jo.menu.create("tailor", { title = "Tailor" })
local stetson = menu:addItem({ title = "Stetson", price = { money = 12.5 } })
menu:send()

-- Later, the player bought the hat
stetson:updateValue("textRight", "Owned")
stetson:updateValue("iconRight", "tick")
menu:push()
Preview

Client jo.menu.addItem() ​

Add an item to a menu from its ID. Same as MenuClass:addItem()

Syntax ​

lua
jo.menu.addItem(id, p, item)

Parameters ​

id : string

The menu ID

p : integer|table

The position of the item in the menu, or the item itself to add it at the end

item : table Optional

The item to add, when p is a position. See MenuClass:addItem() for the keys

Example ​

lua
jo.menu.create("tailor", { title = "Tailor" })
jo.menu.addItem("tailor", { title = "Stetson", icon = "hats" })
jo.menu.addItem("tailor", 1, { title = "Remove the hat" })
jo.menu.send("tailor")

Client jo.menu.delete() ​

Delete a menu, in Lua and in the NUI

Syntax ​

lua
jo.menu.delete(id)

Parameters ​

id : string

The menu ID

Example ​

lua
jo.menu.delete("tailor")
print(jo.menu.isExist("tailor")) -- false

Client jo.menu.get() ​

Get a menu from its ID

Syntax ​

lua
jo.menu.get(id)

Parameters ​

id : string

The menu ID

Return Value ​

Type : MenuClass

The menu object

Example ​

lua
local menu = jo.menu.get("tailor")
menu:updateValue("subtitle", "Hats")
menu:push()

Client jo.menu.isExist() ​

Check if a menu exists

Syntax ​

lua
jo.menu.isExist(id)

Parameters ​

id : string

The menu ID

Return Value ​

Type : boolean

Returns true if the menu exists

Example ​

lua
if not jo.menu.isExist("tailor") then
  createTailorMenu()
end

Client jo.menu.refresh() ​

Refresh a menu from its ID. Same as MenuClass:refresh()

Syntax ​

lua
jo.menu.refresh(id)

Parameters ​

id : string

The menu ID

Example ​

lua
jo.menu.addItem("tailor", { title = "Top hat" })
jo.menu.refresh("tailor")

Client jo.menu.reset() ​

Reset a menu from its ID. Same as MenuClass:reset()

Syntax ​

lua
jo.menu.reset(id)

Parameters ​

id : string

The menu ID

Example ​

lua
jo.menu.reset("tailor")

Client jo.menu.send() ​

Send a menu to the NUI from its ID. Same as MenuClass:send()

Syntax ​

lua
jo.menu.send(id)

Parameters ​

id : string

The menu ID

Example ​

lua
jo.menu.create("tailor", { title = "Tailor" })
jo.menu.addItem("tailor", { title = "Stetson" })
jo.menu.send("tailor")

Client jo.menu.set() ​

Replace the menu stored with this ID

Syntax ​

lua
jo.menu.set(id, menu)

Parameters ​

id : string

The menu ID

menu : MenuClass

The menu

Example ​

lua
local menu = jo.menu.get("tailor")
jo.menu.set("tailor_copy", menu)

Client jo.menu.sort() ​

Sort the items of a menu from its ID. Same as MenuClass:sort()

Syntax ​

lua
jo.menu.sort(id, first, last)

Parameters ​

id : string

The menu ID

first : integer Optional

The position of the first item to sort
default: 1

last : integer Optional

The position of the last item to sort
default: the last item

Example ​

lua
jo.menu.sort("tailor")
jo.menu.refresh("tailor")

Client jo.menu.updateItem() ​

DEPRECATED

since v2.3.0. Use MenuClass:updateValue() or MenuItem:updateValue() then MenuClass:push() instead

Overwrite a property of an item from the menu ID. The NUI is not updated

Syntax ​

lua
jo.menu.updateItem(id, index, key, value)

Parameters ​

id : string

The menu ID

index : integer

The index of the item to update

key : string

The property name to update

value : any

The new value for the property

Example ​

lua
-- Deprecated: use updateValue() then push()
local menu = jo.menu.get("tailor")
menu:updateValue({ "items", 2, "title" }, "Bowler hat")
menu:push()

Display ​

Client jo.menu.displayLoader() ​

Display a loading animation in the menu

Syntax ​

lua
jo.menu.displayLoader(value)

Parameters ​

value : boolean Optional

false to hide the loader
default: true

Example ​

lua
jo.menu.displayLoader()
local outfits = jo.callback.triggerServer("myResource:getOutfits")
-- build the menu with the outfits...
jo.menu.hideLoader()
Preview

Client jo.menu.forceBack() ​

Go back to the previous menu of the history, like Backspace

Syntax ​

lua
jo.menu.forceBack()

Example ​

lua
menu:addItem({
  title = "Validate",
  onClick = function()
    -- save the choice, then go back to the previous menu
    jo.menu.forceBack()
  end,
})

Client jo.menu.hideLoader() ​

Hide the loading animation

Syntax ​

lua
jo.menu.hideLoader()

Example ​

lua
jo.menu.displayLoader()
Wait(1000)
jo.menu.hideLoader()

Client jo.menu.isOpen() ​

Check if the menu is displayed

Syntax ​

lua
jo.menu.isOpen()

Return Value ​

Type : boolean

Returns true if the menu is displayed

Example ​

lua
RegisterCommand("tailor", function()
  if jo.menu.isOpen() then return end
  jo.menu.setCurrentMenu("tailor")
  jo.menu.show(true)
end)

Client jo.menu.isSoftHidden() ​

Check if the menu is hidden by jo.menu.softHide()

Syntax ​

lua
jo.menu.isSoftHidden()

Return Value ​

Type : boolean

Returns true during the execution of the jo.menu.softHide() function

Example ​

lua
CreateThread(function()
  while jo.menu.isOpen() do
    if not jo.menu.isSoftHidden() then
      -- draw something only when the menu is visible
    end
    Wait(0)
  end
end)

Client jo.menu.setCurrentMenu() ​

Set the current menu: the one displayed by jo.menu.show()
If the menu doesn't exist, the handler registered with jo.menu.missingMenuHandler() is called

Syntax ​

lua
jo.menu.setCurrentMenu(id, keepHistoric, resetMenu)

Parameters ​

id : string

The menu ID

keepHistoric : boolean Optional

Keep the previous menu in the history, to go back to it with Backspace
default: true

resetMenu : boolean Optional

Move the cursor back to the first item
default: true

Example ​

lua
-- Open the menu, with the cursor on the first item
jo.menu.setCurrentMenu("tailor")
jo.menu.show(true)

-- Open a menu without history: Backspace won't go back to "tailor"
jo.menu.setCurrentMenu("hats", false)

-- Go back to a menu without moving its cursor
jo.menu.setCurrentMenu("tailor", true, false)
Preview

Client jo.menu.show() ​

Show or hide the current menu
While the menu is displayed, the radar is hidden and the weapon wheel and pause menu controls are disabled

WARNING

The first menu doesn't close itself with Backspace: hide it in its onBack callback. See Go back.

Syntax ​

lua
jo.menu.show(show, keepInput, hideRadar, playMenuAnimation, hideCursor)

Parameters ​

show : boolean

true to show the menu, false to hide it

keepInput : boolean Optional

Keep the game controls active, to move the player while the menu is open
default: true

hideRadar : boolean Optional

Unused: the radar is always hidden while the menu is displayed
default: true

playMenuAnimation : boolean Optional

Play the open/close animation
default: true

hideCursor : boolean Optional

Hide the mouse cursor
default: false

Example ​

lua
-- Show the menu, the player can move
jo.menu.show(true)

-- Show the menu and block the game controls
jo.menu.show(true, false)

-- Hide the menu
jo.menu.show(false)

Client jo.menu.softHide() ​

Hide the menu during the execution of a function, then display it again
The function is executed synchronously: jo.menu.softHide() returns once the menu is displayed again

Syntax ​

lua
jo.menu.softHide(cb, playMenuAnimation, keepBackground)

Parameters ​

cb : function

The function executed while the menu is hidden

playMenuAnimation : boolean Optional

Play the open/close animation
default: true

keepBackground : boolean Optional

Keep the dark background of the menu while it's hidden
default: false

Example ​

lua
menu:addItem({
  title = "Try on",
  onClick = function()
    -- Hide the menu 3 seconds, keep its background
    jo.menu.softHide(function()
      Wait(3000)
    end, true, true)
  end,
})
Preview

Current State ​

Client jo.menu.doesActiveButtonChange() ​

Check if the active item (or the menu) changed during the last update
Useful in onChange callbacks, to know if a slider moved or if the cursor moved

Syntax ​

lua
jo.menu.doesActiveButtonChange()

Return Value ​

Type : boolean

Returns true if the active item changed

Example ​

lua
menu:addItem({
  title = "Stetson",
  sliders = { { title = "Variation", values = { 1, 2, 3 } } },
  onChange = function(currentData)
    if jo.menu.doesActiveButtonChange() then return end
    print("The slider moved to", currentData.item.sliders[1].value)
  end,
})

Client jo.menu.getCurrentData() ​

Get the current state of the menu: the data passed to all the callbacks

Syntax ​

lua
jo.menu.getCurrentData()

Return Value ​

Type : table

{menu = menuID, index = activeItemIndex, item = activeItem}

Example ​

lua
local data = jo.menu.getCurrentData()
print(data.menu, data.index, data.item.title)

Client jo.menu.getCurrentIndex() ​

Get the index of the active item of the current menu

Syntax ​

lua
jo.menu.getCurrentIndex()

Return Value ​

Type : integer

The index of the active item

Example ​

lua
local index = jo.menu.getCurrentIndex()
print("The active item is the item", index)

Client jo.menu.getCurrentItem() ​

Get the active item of the current menu

Syntax ​

lua
jo.menu.getCurrentItem()

Return Value ​

Type : MenuItemClass

The active item

Example ​

lua
local item = jo.menu.getCurrentItem()
print(item.title)

Client jo.menu.getCurrentMenu() ​

Get the current menu

Syntax ​

lua
jo.menu.getCurrentMenu()

Return Value ​

Type : MenuClass

The current menu

Example ​

lua
local menu = jo.menu.getCurrentMenu()
print(menu.title)

Client jo.menu.getCurrentMenuId() ​

Get the ID of the current menu

Syntax ​

lua
jo.menu.getCurrentMenuId()

Return Value ​

Type : string

The ID of the current menu

Example ​

lua
if jo.menu.getCurrentMenuId() == "tailor" then
  print("The player is in the tailor menu")
end

Client jo.menu.getPreviousData() ​

Get the state of the menu before the last change

Syntax ​

lua
jo.menu.getPreviousData()

Return Value ​

Type : table

{menu = menuID, index = activeItemIndex, item = activeItem}

Example ​

lua
menu:addItem({
  title = "Stetson",
  onActive = function(currentData)
    local previous = jo.menu.getPreviousData()
    print("Previous item:", previous.item and previous.item.title)
  end,
})

Client jo.menu.isCurrentMenu() ​

Check if a menu is the current menu and is displayed

Syntax ​

lua
jo.menu.isCurrentMenu(id)

Parameters ​

id : string

The menu ID

Return Value ​

Type : boolean

Returns true if the menu is displayed and is the current one

Example ​

lua
if jo.menu.isCurrentMenu("tailor") then
  jo.menu.get("tailor"):refresh()
end

Events ​

Client jo.menu.fireAllLevelsEvent() ​

Fire an event on the current menu, then on its active item

Syntax ​

lua
jo.menu.fireAllLevelsEvent(eventName, ...)

Parameters ​

eventName : string

The name of the event, like onTick

... : any Optional

Additional arguments for the listeners

Example ​

lua
-- Fire the onTick of the current menu and of its active item
jo.menu.fireAllLevelsEvent("onTick")

Client jo.menu.fireEvent() ​

Fire an event of a menu or an item
The listeners receive the current data (see jo.menu.getCurrentData()) followed by the additional arguments
The client and server events defined with <eventName>ClientEvent and <eventName>ServerEvent keys are triggered too

Syntax ​

lua
jo.menu.fireEvent(item, eventName, ...)

Parameters ​

item : table

The menu or the item

eventName : string

The name of the event, like onClick

... : any Optional

Additional arguments for the listeners

Example ​

lua
-- Fire the onActive callback of the active item again
jo.menu.fireEvent(jo.menu.getCurrentItem(), "onActive")

-- With additional arguments
jo.menu.fireEvent(jo.menu.getCurrentMenu(), "onRefresh", "myArgument")

Client jo.menu.missingMenuHandler() ​

Register a function to create a menu the first time it's needed
Called when jo.menu.setCurrentMenu() or an item child targets this menu ID and the menu doesn't exist

Syntax ​

lua
jo.menu.missingMenuHandler(id, callback)

Parameters ​

id : string

The menu ID

callback : function

The function that creates the menu

Example ​

lua
-- The "hats" menu is created the first time it's opened
jo.menu.missingMenuHandler("hats", function()
  local hats = jo.menu.create("hats", { title = "Tailor", subtitle = "Hats" })
  hats:addItem({ title = "Stetson" })
  hats:send()
  hats:use(true)
end)

local menu = jo.menu.create("tailor", { title = "Tailor" })
menu:addItem({ title = "Hats", child = "hats" })
menu:send()

Client jo.menu.onChange() ​

Listen to all the changes of all the menus: active item, sliders, menu
The callback receives {menu, index, item}. It's unregistered when the resource stops

Syntax ​

lua
jo.menu.onChange(cb)

Parameters ​

cb : function

The function fired on each change

Example ​

lua
jo.menu.onChange(function(data)
  print(("Menu %s, item %d: %s"):format(data.menu, data.index, data.item.title))
end)

Client jo.menu.runRefreshEvents() ​

Fire the events of the current menu again, as if it was just opened

Syntax ​

lua
jo.menu.runRefreshEvents(menuEvent, itemEvent)

Parameters ​

menuEvent : boolean Optional

Fire onExit and onEnter of the menu, and onExit and onActive of the item
default: false

itemEvent : boolean Optional

Fire onExit and onActive of the active item
default: false

Example ​

lua
-- Fire onExit and onActive of the active item again
jo.menu.runRefreshEvents(false, true)

Settings ​

Client jo.menu.playAudio() ​

Play a sound of the menu

Syntax ​

lua
jo.menu.playAudio(sound)

Parameters ​

sound : string

The sound name: button, coins, menu_open, menu_close or selected

Example ​

lua
menu:addItem({
  title = "Buy",
  onClick = function()
    jo.menu.playAudio("coins")
  end,
})

Client jo.menu.updateLang() ​

Translate the texts of the menu
You can also add your own keys, used by the translate* options of the menus, items and sliders

TIP

You can add your own keys and use them with the translate* options. See Translations.

Syntax ​

lua
jo.menu.updateLang(lang)

Parameters ​

lang : table

The translated strings, by key

lang.of : string - The counter of the items and sliders. %1 is the current position, %2 the total
default: "%1 of %2" Optional

lang.price : string - The label above the price
default: "Price" Optional

lang.devise : string - The currency symbol
default: "$" Optional

lang.free : string - The text displayed when the price is 0
default: "Free" Optional

lang.number : string - The title of an item without title. %1 is the item position
default: "Number %1" Optional

Example ​

lua
jo.menu.updateLang({
  of = "%1 sur %2",
  price = "Prix",
  devise = "€",
  free = "Gratuit",
  number = "Numéro %1",
})
Preview

Client jo.menu.updateVolume() ​

Set the volume of the menu sounds

Syntax ​

lua
jo.menu.updateVolume(volume)

Parameters ​

volume : number

The volume, from 0.0 to 1.0
default: 0.5

Example ​

lua
jo.menu.updateVolume(0.2)

Last updated: