diegofkda Posted December 2, 2011 Share Posted December 2, 2011 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
unknooooown Posted December 2, 2011 Share Posted December 2, 2011 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 Link to comment
diegofkda Posted December 2, 2011 Author Share Posted December 2, 2011 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
unknooooown Posted December 2, 2011 Share Posted December 2, 2011 I have to go now, but if noone else has helped you when I get back, I will have a look Link to comment
diegofkda Posted December 2, 2011 Author Share Posted December 2, 2011 Well, no problem. I believe it's an MTA bug. Link to comment
50p Posted December 2, 2011 Share Posted December 2, 2011 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
DiSaMe Posted December 2, 2011 Share Posted December 2, 2011 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
Xeno Posted December 2, 2011 Share Posted December 2, 2011 Why are you using destroyElement? Use: guiSetVisible(currentWindow, false) And, its not createWindow. element guiCreateWindow ( float x, float y, float width, float height, string titleBarText, bool relative ) https://wiki.multitheftauto.com/wiki/GuiCreateWindow Link to comment
unknooooown Posted December 2, 2011 Share Posted December 2, 2011 Xeno, please note: btw createWindow is a custom function for a custom GUI Link to comment
Xeno Posted December 2, 2011 Share Posted December 2, 2011 Xeno, please note: btw createWindow is a custom function for a custom GUI Sorry, didn't read properly. Link to comment
50p Posted December 2, 2011 Share Posted December 2, 2011 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
diegofkda Posted December 3, 2011 Author Share Posted December 3, 2011 The createWindow returns a static image btw guys, and I want to destroy it because of 50p reasons and my scripting ways. 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