dxGetTextWidth | Multi Theft Auto: Wiki Skip to content

dxGetTextWidth

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function retrieves the theoretical width (in pixels) of a certain piece of text, if it were to be drawn using dxDrawText.

OOP Syntax Help! I don't understand this!

  • Note: This syntax requires you to ignore the font argument above

  • Method: font:getTextWidth(...)

Syntax

float dxGetTextWidth ( string text, [ float scale = 1, mixed font = "default", bool bColorCoded = false ] )
Required Arguments
  • text: A string representing the text for which you wish to retrieve with width for.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • scale (default: 1): MISSING_PARAM_DESC
  • font (default: "default"): MISSING_PARAM_DESC
  • bColorCoded (default: false): MISSING_PARAM_DESC

Returns

  • float: value

Returns the float of the width of the text (in pixels).

Code Examples

shared

This will show you the width of a message in a normal chatbox sent by a player

function dxwidth(msg)
chatbox = getChatboxLayout()
local length = dxGetTextWidth(msg,chatbox["chat_scale"][1])
outputChatBox(tostring(length))
end
addEventHandler("onClientChatMessage",root,dxwidth)