jkub Posted October 18, 2011 Share Posted October 18, 2011 I really can't stand having to use redundant code anymore it takes long to do and it makes my scripts look like shit. Anyway in this instance I am having a major problem with a housing system I am making. I am currently working on the gui and in this "wizard" I created is like 19 gui edit fields. I also have a create button in the lower corner. When I click the create button it should only pass the data onto the server IF ALL of the text fields are filled in. The big problem with that is the only way I know to check all of them is to individually do if guiGetText ( blahblahfield) == "" then..... and that will end up being really long and stupid and pissing me off. I thought of a way myself to get all the children of the wizard GUI and then single out the edit fields. Only problem with that is there is no way to get the type of gui element. for example a button or edit field etc... Please help me. Link to comment
Aibo Posted October 18, 2011 Share Posted October 18, 2011 -- you can check gui elements' type, and editbox element type is "gui-edit": for i, element in ipairs(getElementChildren(someParentElement)) do if getElementType(element) == "gui-edit" then -- your check or whatever goes here end end ------------------------------------------------------------------------------------- -- you can also put all your edits in a table like: myEdits = {} myEdits[1] = guiCreateEdit(blablabla) myEdits[2] = guiCreateEdit(blablabla) -- etc. -- and then just loop through them and check: for i, edit in ipairs(myEdits) do -- your check or whatever goes here end Link to comment
qaisjp Posted October 18, 2011 Share Posted October 18, 2011 -- you can check gui elements' type, and editbox element type is "gui-edit": function isEditsFull() for i, element in ipairs(getElementChildren(someParentElement)) do if getElementType(element) == "gui-edit" then if guiGetText(element) == "" then return false end end return true end end ------------------------------------------------------------------------------------- -- you can also put all your edits in a table like: myEdits = {} myEdits[1] = guiCreateEdit(blablabla) myEdits[2] = guiCreateEdit(blablabla) -- etc. -- and then just loop through them and check: function isEditsFull() for i, edit in ipairs(myEdits) do if guiGetText(edit) == "" then return false end end return true end returns a true value IF HAS text Link to comment
Castillo Posted October 18, 2011 Share Posted October 18, 2011 Isn't also possible to do something like this: myEdit1 = guiCreateEdit(args...) myEdit2 = guiCreateEdit(args...) edits = {myEdit1, myEdit2} function checkEdits() for index, element in ipairs(edits) do if not isElement(element) then return end if guiGetText(element) == "" then return false else return true end end end Link to comment
qaisjp Posted October 18, 2011 Share Posted October 18, 2011 We are checking if any of the following ones are NOT "". What you did is return a value depending on the first one. Return kills the loop too and will kill it on the first loop. SO no, that wont work castillo. Link to comment
jkub Posted October 18, 2011 Author Share Posted October 18, 2011 Thank you guys for the speedy help. I will try this today and check up back here afterwards! Link to comment
jkub Posted October 18, 2011 Author Share Posted October 18, 2011 Thanks again, I am happy to say that it works. Now about something, I want to pass all this data serverside. I tried sticking all the gui edits in a table and creating another table with their text and sending it server side but for some reason every time it only adds the very first gui edit to the table. elseif source == create_Btn then for i, element in pairs(getElementChildren(addTab)) do if getElementType(element) == "gui-edit" then if guiGetText(element) == "" or guiComboBoxGetSelected ( combobox_Class ) == -1 or guiComboBoxGetSelected ( combobox_Int ) == -1 or guiComboBoxGetSelected ( combobox_Dim ) == -1 then outputChatBox ( "ERROR, make sure all information is entered", 255, 0, 0 ) ready = false return false else int = guiComboBoxGetItemText ( combobox_Class, guiComboBoxGetSelected ( combobox_Class ) ) dim = guiComboBoxGetItemText ( combobox_Dim, guiComboBoxGetSelected ( combobox_Dim ) ) class = guiComboBoxGetItemText ( combobox_Int, guiComboBoxGetSelected ( combobox_Int ) ) table.insert ( guiEditInputs, guiGetText(element) ) ready = true break end end end if ready == true then triggerServerEvent ( "addPropertyToDatabase", getLocalPlayer(), int, dim, class, guiEditInputs ) end end Link to comment
Aibo Posted October 18, 2011 Share Posted October 18, 2011 because you're setting ready=true at first iteration and then exiting the loop using break. you dont really need break/ready stuff, it will stop and event wont be triggered after "return false" elseif source == create_Btn then for i, element in pairs(getElementChildren(addTab)) do if getElementType(element) == "gui-edit" then if guiGetText(element) == "" or guiComboBoxGetSelected ( combobox_Class ) == -1 or guiComboBoxGetSelected ( combobox_Int ) == -1 or guiComboBoxGetSelected ( combobox_Dim ) == -1 then outputChatBox ( "ERROR, make sure all information is entered", 255, 0, 0 ) return false else int = guiComboBoxGetItemText ( combobox_Class, guiComboBoxGetSelected ( combobox_Class ) ) dim = guiComboBoxGetItemText ( combobox_Dim, guiComboBoxGetSelected ( combobox_Dim ) ) class = guiComboBoxGetItemText ( combobox_Int, guiComboBoxGetSelected ( combobox_Int ) ) table.insert(guiEditInputs, guiGetText(element)) end end end triggerServerEvent ( "addPropertyToDatabase", getLocalPlayer(), int, dim, class, guiEditInputs ) end Link to comment
jkub Posted October 18, 2011 Author Share Posted October 18, 2011 Thanks aibo, for clearing that up for me. I find it often that the simple things are what I end up overlooking. Link to comment
50p Posted October 19, 2011 Share Posted October 19, 2011 Have you tried my GUI classes? That's probably what you may be interested in. It makes scripting GUI easier and more readable. It also has a feature for dragable controls. viewtopic.php?f=108&t=24122 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