Matei02Mihai Posted December 31, 2022 Share Posted December 31, 2022 Hello. I created a test hud and i added a button using dgs. The problem is, when i add that button, the script doesn't show nothing. If i delete all the lines where i use this language, the hud is showing normally. I'm new in this language and i don't know exactly how to use another languages than the default. I used a hud downloaded from resources section as an example. Code: loadstring(exports.dgs:dgsImportFunction())() loadstring(exports.dgs:dgsImportOOPClass(true))() local screensize = Vector2(guiGetScreenSize()) local buttonsize = Vector2(100, 50) local windowsize = Vector2(400, 400) local windowfinal = Vector2(screensize.x/2 - windowsize.x/2, screensize.y/2 - windowsize.y/2) local buttonfinal = Vector2(screensize.x/2 - buttonsize.x/2, screensize.y/2 - buttonsize.y/2) function paneltest() dxDrawImage(windowfinal.x, windowfinal.y, windowsize.x, windowsize.y, 'panels/window.png', 0, 0, 0, tocolor(255, 255, 255, 150), false) dxDrawImage(windowfinal.x, windowfinal.y, windowsize.x, windowsize.y, 'panels/window2.png') dgsCreateButton(buttonfinal.x, buttonfinal.y, buttonsize.x, buttonsize.y, "Test", true) dxDrawText("JobInfo", windowfinal.x+180, windowfinal.y) end addEventHandler("onClientRender", root, function() paneltest() end ) meta.xml: <meta> <info author="matei123" type="script" version="1.0.0" /> <script src="code.lua" type="server" /> <script src="gui.lua" type="client" /> <file src='panels/window.png' /> <file src='panels/window2.png' /> </meta> Link to comment
Trust aka Tiffergan Posted December 31, 2022 Share Posted December 31, 2022 @Matei02Mihai It looks like you're trying to create a button using the dgsCreateButton function, but it's not appearing on the screen. There are a few things you could try to troubleshoot this issue: Make sure that you have correctly imported the dgs library and the OOP classes by using the dgsImportFunction and dgsImportOOPClass functions. These functions should be called before you try to use any dgs functions or classes. Make sure that the paneltest function is being called correctly. You can add a print statement at the beginning of the function to verify that it's being called correctly. Make sure that you have correctly defined the position and size of the button using the buttonfinal.x, buttonfinal.y, buttonsize.x, and buttonsize.y variables. These variables should be set to the desired position and size of the button. Make sure that you are not accidentally covering up the button with other GUI elements. You can try changing the draw order of your GUI elements to make sure that the button is being drawn on top of other elements. Link to comment
Scripting Moderators xLive Posted December 31, 2022 Scripting Moderators Share Posted December 31, 2022 (edited) Do not use DGS functions in the render event. Using dgsCreateButton in onClientRender will create a new button every frame, which can cause the game to crash. Instead, use dgsCreateButton only once to create the button. You don't need to use any render or DX functions when working with DGS. You can use dgsCreateImage to create images and dgsCreateLabel for texts. It's also unclear why you are enabling DGS OOP if you are not using it. If you are having issues with your code, it's helpful to learn about debugging. Edited December 31, 2022 by xLive 1 Link to comment
Scripting Moderators thisdp Posted January 1, 2023 Scripting Moderators Share Posted January 1, 2023 The main reason of the missing button is that you are using "absolute position / size" but you put a "true" in "relative" argument which means you need "relative position / size". 1 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