Community Forum

Loading GUI (g_gui:loadGui)

Forum Overview >> Scripting

Created23.01.2019 22:51

Wieger Jan Schaap (wjschaap) 23.01.2019 22:51
We want to load and show a gui in a function, who is activated by a defined keybinding (left ctrl+f). We try, but we get a Lua error in the update method of the mod. We are looking for the basics to show a gui, so we can understand what happen en how we must use g_gui:loadGui and g_gui:showGui. We hope someone can and will help us. Thank you.

Jonas A. L. Andersen (StjerneIdioten) 24.01.2019 11:30
From my understanding input handling now happens through actions instead of checking for input in the update loop. So you register your action with a callback and then this callback function will get called when your action is activated. And then you would probably set some variables, which would adjust how your GUI looks. And then in the onDraw function you would handle all of the stuff that actually shows your GUI.

If you look around for the "TSX_EnhancedVehicle" mod, you can probably find their FS19 version. And if you look through their code you should probably get an idea about how the new action system works and the GUI, depending on how elaborate this GUI of yours is of course. I think the TSX mod only shows some stuff and have no interaction element too it. But I don't know from your question whether you are trying to create a menu or just show some stuff on the screen.

Wieger Jan Schaap (wjschaap) 24.01.2019 12:22
Thank you for your reply. A little more context. We are working on a Financial Manager for FS19. One of the features is, you could make invoices for other farms for the tasks you did for them. We are now working on the GUI to activate the Financial Manager en make it possible to make an invoice. We struggle a bit to load a gui.

We are also enthusiast users of the "TSX_EnhancedVehicle" mod, zo we take a look at the code.

Jos Kuijpers (Unknown) 24.01.2019 15:25
Might be good to share the lua error

Pokke Pinguin (Pokkepinguin) 24.01.2019 21:12
Hi Jos,

This is the error we get:

2019-01-24 21:10 Error: Running LUA method 'update'.
2019-01-24 21:10 dataS/scripts/gui/base/Gui.lua(199) : attempt to index local 'controller' (a nil value)

Hope you can help us out;)

Thanks in advance

Kind regards,

Jos Kuijpers (Unknown) 25.01.2019 16:25
Your third parameter is missing:
local instance = MyClass:new()
g_gui:loadGui("path/to/XML.xml", "MyClass", instance, true)

Pokke Pinguin (Pokkepinguin) 28.01.2019 21:01
Hi Jos,

Thanks for the help! This worked out great for us.

Kind regards,

Note: Log in to post. Create a new account here.