Jump to content

dgs problem


Matei02Mihai

Recommended Posts

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

@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:

  1. 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.

  2. 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.

  3. 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.

  4. 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

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 by xLive
  • Like 1
Link to comment
  • Scripting Moderators

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".

  • Like 1
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...