Answer the question
In order to leave comments, you need to log in
Script error: bad argument #2 to 'format' (number expected, got string) stack traceback: [C]: in function 'format'?
An error occurs when requesting a function:
function SampEvents.onServerMessage(color, msg)
if msg:find('Вы можете взять %d+ материалов.') and not sampIsChatInputActive() then
sampSendChat(string.format('/get guns %d', msg))
end
end
[ML] (error) main.lua: D:\Games\SAMP\moonloader\main.lua:34: bad argument #2 to 'format' (number expected, got string)
stack traceback:
[C]: in function 'format'
D:\Games\SAMP\moonloader\main.lua:34: in function 'callback'
D:\Games\SAMP\moonloader\lib\samp\events\core.lua:80: in function <D:\Games\SAMP\moonloader\lib\samp\events\core.lua:54>
[ML] (error) main.lua: Script died due to error. (1E3671AC)
Answer the question
In order to leave comments, you need to log in
sampSendChat(string.format('/get guns %d', tonumber(msg)))
sampSendChat('/get guns ' .. msg))
The argument to the string.format function is a string, not a number. Change the modifier in the format specifier from %d to %s.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question