ARYDER Posted February 7, 2023 Share Posted February 7, 2023 (edited) Hello everyone! What would be the best solution: 1. Create a GUI outside the general function, hide the element, for example, "window", and show it using another function 2. Create a function with a GUI in it, and show it using this function itself And will I be able to manage GUi elements in the second case? First example: local window = guiCreateWindow (...) local window_element = guiCreateLabel (...) -- window is a parent local other_window_element = guiCreateLabel (...) -- window is a parent guiSetVisible (window, false) function someFunction () guiSetVisible (window, true) showCursor (true) end addEvent ("eventFromServer", true) addEventHandler ("eventFromServer", localPlayer, someFunction) Second example: function someFunction () showCursor (true) window = guiCreateWindow (...) window_element = guiCreateLabel (...) -- window is a parent other_window_element = guiCreateLabel (...) -- window is a parent end addEvent ("eventFromServer", true) addEventHandler ("eventFromServer", localPlayer, someFunction) Thank you. Edited February 7, 2023 by sadvely Link to comment
Scripting Moderators xLive Posted February 7, 2023 Scripting Moderators Share Posted February 7, 2023 (edited) For best performance, create the CEGUI elements only when they are needed, and destroy them when they are no longer being used. Keeping unused elements in memory can lead to performance issues, especially if the player is likely to use them a few times only. However, if you have a lot of CEGUI elements in your window that the player would frequently use. In such cases, it's more efficient to hide/unhide the elements instead of creating and destroying them each time. Edited February 7, 2023 by xLive 1 Link to comment
FLUSHBICEPS Posted February 7, 2023 Share Posted February 7, 2023 In the first case creating and hiding a GUI outside of the main function makes managing the elements easier. To alter the visibility of the gui and its elements use the guiSetVisible function Now the second example is appropriate if you only need to create the GUI once but if you need to show and hide the GUI multiple times, creating it outside the function is more efficient. If you built the GUI inside the function each time it was called, your script would run slower and consume more resources the GUI elements can be managed in both cases because they are global variables that can be referenced from anywhere in the code. 1 Link to comment
ARYDER Posted February 8, 2023 Author Share Posted February 8, 2023 (edited) Thank you guys for the decent answers, quite informative, I will use it in practice. There is another question, perhaps requiring the creation of another topic, but... Can I make some file, let's say, a client lua with GUI element settings? Like that: -- SETTINGS.LUA SOME_SETTINGS = {} SOME_SETTINGS.WINDOW = { X = 0, Y = 0, WIDTH = 300, HEIGHT = 300, NAME = "TITLE", RELATIVE = false } And how should i use it? unpack () doesn't work for me like this: -- CLIENT.LUA guiCreateWindow (unpack (SOME_SETTINGS.WINDOW)) Edited February 8, 2023 by sadvely Link to comment
FLUSHBICEPS Posted February 8, 2023 Share Posted February 8, 2023 -- settings.lua SOME_SETTINGS = {} SOME_SETTINGS.WINDOW = { X = 0, Y = 0, WIDTH = 300, HEIGHT = 300, NAME = "TITLE", RELATIVE = false } -- client.lua include("settings.lua") guiCreateWindow (SOME_SETTINGS.WINDOW.X, SOME_SETTINGS.WINDOW.Y, SOME_SETTINGS.WINDOW.WIDTH, SOME_SETTINGS.WINDOW.HEIGHT, SOME_SETTINGS.WINDOW.NAME, SOME_SETTINGS.WINDOW.RELATIVE) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now