Jump to content

MTA bug or what am I doing wrong?


diegofkda

Recommended Posts

if currentWindow then 
        destroyElement ( currentWindow ) 
end 
currentWindow = createWindow ( 300, 200, 400, 650, "Options" ) 

btw createWindow is a custom function for a custom GUI and my problem is that it doesn't check, "if currentWindow then" reads that currentWindow is always true, so when there is no currentWindow there will be a bad argument destroyElement.

Link to comment

I am not totally sure about what you are trying to do, but try this:

  
currentWindow = createWindow ( 300, 200, 400, 650, "Options" ) 
    if currentWindow then 
            destroyElement ( currentWindow ) 
    end 
  

You should be able to see the changes yourself.

Keep in mind that you cant check if something exists before it has been created.

Well.. You can, but it wont do you any good :P

Link to comment

Next time I should post the whole script.

    if source == resumeButton then 
        openPauseMenu() 
    elseif source == optionsButton then 
        if currentWindow then 
            destroyElement ( currentWindow ) 
        end 
        currentWindow = createWindow ( 300, 200, 400, 650, "Options" ) 
    elseif source == myinfoButton then 
        if currentWindow then 
            destroyElement ( currentWindow ) 
        end 
        currentWindow = createWindow ( 300, 200, 400, 650, "Information" ) 
    elseif source == graphicsButton then 
        if currentWindow then 
            destroyElement ( currentWindow ) 
        end 
        currentWindow = createWindow ( 300, 200, 400, 650, "Graphics" ) 
    end 

It checks if another one was created before, it must destroy it and create a new one.

Link to comment
Next time I should post the whole script.
    if source == resumeButton then 
        openPauseMenu() 
    elseif source == optionsButton then 
        if currentWindow then 
            destroyElement ( currentWindow ) 
        end 
        currentWindow = createWindow ( 300, 200, 400, 650, "Options" ) 
    elseif source == myinfoButton then 
        if currentWindow then 
            destroyElement ( currentWindow ) 
        end 
        currentWindow = createWindow ( 300, 200, 400, 650, "Information" ) 
    elseif source == graphicsButton then 
        if currentWindow then 
            destroyElement ( currentWindow ) 
        end 
        currentWindow = createWindow ( 300, 200, 400, 650, "Graphics" ) 
    end 

It checks if another one was created before, it must destroy it and create a new one.

When you destroy element, the variable still holds its value. So, nil the variable too.

if currentWindow then 
    destroyElement ( currentWindow ) 
    currentWindow = nil; 
end 
currentWindow = createWindow ( 300, 200, 400, 650, "Options" ) 

I don't quite understand what's your goal here.

Link to comment

I also have a question which is related to this topic. Is it reliable to check using isElement instead of setting variable to nil when the element gets destroyed? Variable still holds the address of no longer existing element, so if I understand it correctly, some newly created element may get stored at the same address, forcing the variable to point at the new element and therefore causing isElement to return true, even when old element doesn't exist. Is that right?

Link to comment
Why are you using destroyElement?

Use:

guiSetVisible(currentWindow, false) 

If you hide the window, it is still in the memory. If you have a lot of windows but they're all hidden, then your frame rate may drop (depending on amount of RAM). Remember, not every player has fast PC. Some people have as fast PC as the minimum requirements for MTA. Anyway, you may also want to recreate window if you want to make sure everything is reset.

I also have a question which is related to this topic. Is it reliable to check using isElement instead of setting variable to nil when the element gets destroyed? Variable still holds the address of no longer existing element, so if I understand it correctly, some newly created element may get stored at the same address, forcing the variable to point at the new element and therefore causing isElement to return true, even when old element doesn't exist. Is that right?

Well, I haven't had that happening yet, probably because I haven't had that many elements. My thinking about this is that you have to reach certain address to get other elements created at old/destroyed elements address. Ideally, set the variable to nil. This will make sure that variable is freed from memory and let you know that element does not exist.

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