Jump to content

GUI Creating


sadvely

Recommended Posts

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 by sadvely
Link to comment
  • Scripting Moderators

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 by xLive
  • Thanks 1
Link to comment

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.

  • Thanks 1
Link to comment

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 by sadvely
Link to comment
-- 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...