[mimgui] imgui.Combo

sat0ry

Известный
Автор темы
1,092
296
Версия MoonLoader
.026-beta
Код:
Lua:
require('moonloader')
local ffi = require 'ffi'
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local new, str, sizeof = imgui.new, ffi.string, ffi.sizeof

local renderWindow = new.bool(false)

local combo = new.int(1)

local combo_table = {u8'Картофель-Фри', u8'Биг-Мак'}

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
end)

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 300, 300
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin('Main Window', renderWindow)
        imgui.Combo('Combo', combo, combo_table)
        imgui.End()
    end
)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand('mimgui', function()
        renderWindow[0] = not renderWindow[0]
    end)

    wait(-1)
end

Ошибка:

Lua:
[ML] (error) testthemes.lua: D:\Babetape_LetoGTA\moonloader\testthemes.lua:28: bad argument #3 to 'Combo' (cannot convert 'table' to 'const char *const *')
stack traceback:
    [C]: in function 'Combo'
    D:\Babetape_LetoGTA\moonloader\testthemes.lua:28: in function '_draw'
    D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:102: in function <D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:86>
[ML] (error) testthemes.lua: Script died due to an error. (0BF9EC0C)

Помогите пж
 
Решение
Lua:
ML] (error) timetime.lua: D:\Babetape_LetoGTA\moonloader\timetime.lua:31: bad argument #5 to 'Combo' (cannot convert 'string' to 'int')
stack traceback:
    [C]: in function 'Combo'
    D:\Babetape_LetoGTA\moonloader\timetime.lua:31: in function '_draw'
    D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:102: in function <D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:86>
[ML] (error) timetime.lua: Script died due to an error. (0C5DACBC)
Чувствую это будет бесконечно длиться
Если научиться искать, то не будет

RedHolms

Известный
Проверенный
619
366
Код:
Lua:
require('moonloader')
local ffi = require 'ffi'
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local new, str, sizeof = imgui.new, ffi.string, ffi.sizeof

local renderWindow = new.bool(false)

local combo = new.int(1)

local combo_table = {u8'Картофель-Фри', u8'Биг-Мак'}

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
end)

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 300, 300
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin('Main Window', renderWindow)
        imgui.Combo('Combo', combo, combo_table)
        imgui.End()
    end
)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand('mimgui', function()
        renderWindow[0] = not renderWindow[0]
    end)

    wait(-1)
end

Ошибка:

Lua:
[ML] (error) testthemes.lua: D:\Babetape_LetoGTA\moonloader\testthemes.lua:28: bad argument #3 to 'Combo' (cannot convert 'table' to 'const char *const *')
stack traceback:
    [C]: in function 'Combo'
    D:\Babetape_LetoGTA\moonloader\testthemes.lua:28: in function '_draw'
    D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:102: in function <D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:86>
[ML] (error) testthemes.lua: Script died due to an error. (0BF9EC0C)

Помогите пж
Lua:
COMBOS_TABLE = {...}

local curentCombo = imgui.new["int"]()
local combos = imgui.new["const char**"](COMBOS_TABLE)


imgui.Combo("label", curentCombo, combos, #COMBOS_TABLE, ...)
 

sat0ry

Известный
Автор темы
1,092
296
Lua:
COMBOS_TABLE = {...}

local curentCombo = imgui.new["int"]()
local combos = imgui.new["const char**"](COMBOS_TABLE)


imgui.Combo("label", curentCombo, combos, #COMBOS_TABLE, ...)
Lua:
[ML] (error) timetime.lua: D:\Babetape_LetoGTA\moonloader\timetime.lua:15: cannot convert 'string' to 'const char **'
stack traceback:
    [C]: in function 'const char**'
    D:\Babetape_LetoGTA\moonloader\timetime.lua:15: in main chunk
[ML] (error) timetime.lua: Script died due to an error. (25780FEC)
 

RedHolms

Известный
Проверенный
619
366
Lua:
[ML] (error) timetime.lua: D:\Babetape_LetoGTA\moonloader\timetime.lua:15: cannot convert 'string' to 'const char **'
stack traceback:
    [C]: in function 'const char**'
    D:\Babetape_LetoGTA\moonloader\timetime.lua:15: in main chunk
[ML] (error) timetime.lua: Script died due to an error. (25780FEC)
maybe
Lua:
local combos = imgui.new["const char*[]"](COMBOS_TABLE)
 

sat0ry

Известный
Автор темы
1,092
296
maybe
Lua:
local combos = imgui.new["const char*[]"](COMBOS_TABLE)
Код:
[ML] (error) timetime.lua: D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:350: size of C type is unknown or too large
stack traceback:
    [C]: in function 'typeof'
    D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:350: in function '__index'
    D:\Babetape_LetoGTA\moonloader\timetime.lua:15: in main chunk
[ML] (error) timetime.lua: Script died due to an error. (0AAA49D4)
 

RedHolms

Известный
Проверенный
619
366
Код:
[ML] (error) timetime.lua: D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:350: size of C type is unknown or too large
stack traceback:
    [C]: in function 'typeof'
    D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:350: in function '__index'
    D:\Babetape_LetoGTA\moonloader\timetime.lua:15: in main chunk
[ML] (error) timetime.lua: Script died due to an error. (0AAA49D4)
Lua:
local combos = imgui.new["const char*"][#COMBOS_TABLE](COMBOS_TABLE)
 
  • Нравится
Реакции: sat0ry

sat0ry

Известный
Автор темы
1,092
296
Lua:
local combos = imgui.new["const char*"][#COMBOS_TABLE](COMBOS_TABLE)
Lua:
ML] (error) timetime.lua: D:\Babetape_LetoGTA\moonloader\timetime.lua:31: bad argument #5 to 'Combo' (cannot convert 'string' to 'int')
stack traceback:
    [C]: in function 'Combo'
    D:\Babetape_LetoGTA\moonloader\timetime.lua:31: in function '_draw'
    D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:102: in function <D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:86>
[ML] (error) timetime.lua: Script died due to an error. (0C5DACBC)
Чувствую это будет бесконечно длиться
 

RTD

Потужно
Модератор
399
470
Lua:
ML] (error) timetime.lua: D:\Babetape_LetoGTA\moonloader\timetime.lua:31: bad argument #5 to 'Combo' (cannot convert 'string' to 'int')
stack traceback:
    [C]: in function 'Combo'
    D:\Babetape_LetoGTA\moonloader\timetime.lua:31: in function '_draw'
    D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:102: in function <D:\Babetape_LetoGTA\moonloader\lib\mimgui\init.lua:86>
[ML] (error) timetime.lua: Script died due to an error. (0C5DACBC)
Чувствую это будет бесконечно длиться
Если научиться искать, то не будет
 
  • Влюблен
Реакции: sat0ry

sat0ry

Известный
Автор темы
1,092
296
Если научиться искать, то не будет
Принцип combo отличается у mimgui и imgui. Я даже не мог представить, что для использования таблицы нужно проделать столько манипуляций.