Skip to content

MySQL_GetJSONInt

imshooter edited this page Oct 24, 2026 · 1 revision

A value of a JSON cell as an integer.

native MySQL_GetJSONInt(row, const field[], const key[], fallback = 0);

Parameters

Parameter Description Default
row The row, from 0.
const field[] Name of the field.
const key[] Member of the top object or a JSON Pointer.
fallback What it gives when the value does not exist, is null, or is an object or an array. 0

Remarks

A float is cut to a whole number, a boolean reads as 0 or 1 and a string holding a number is read as that number. A key the cell lacks gives fallback, so a value added in a later version of a script has a default for the rows saved before.

Example

forward OnItemRead(itemid);

public OnItemRead(itemid) {
    new const
        amount = MySQL_GetJSONInt(0, "attributes", "amount", 1),
        Float:condition = MySQL_GetJSONFloat(0, "attributes", "condition", 100.0),
        bool:locked = MySQL_GetJSONBool(0, "attributes", "locked")
    ;

    printf("item %i: %i, %.1f%%, %s", itemid, amount, condition, locked ? ("locked") : ("open"));

    return 1;
}

Related

Clone this wiki locally