Finding an item in a collection of types
Blitz3D Forums/Blitz3D Programming/Finding an item in a collection of types
| ||
Okay here is the issue. I have 5 or 6 checkboxes for the gui i am desigining. And each is a type. Each is assigned a unique name. However, i want to be able to get the state/value of that checkbox, but simply passing its unique name into a function. The code below works. But if its called every game loop one function slows the entire game down immensely. Anyone know a better way to do this? ;========================================================== ;GET THE VALUE OF THE GIVEN CHECK BOX ;========================================================= Function GUI_GET_CHECKBOX_VAL( CHECKBOXNAMESTR$ ) For TARGET_CHECK.GUI_CHECKBOX_TYPE=Each GUI_CHECKBOX_TYPE If TARGET_CHECK\NAME$ = CHECKBOXNAMESTR$ Then Return TARGET_CHECK\Value End If Next End Function |
| ||
well you could use handles... like have instead of a name the function would return a handle then you could just do TargetCheck.Gui = Object.Target(handle) return TargetCheck\Value |
| ||
5 or 6 types shouldn't slow it down that much! should it? |
| ||
DrakeX , well, i think it super slow because i was using the function inefficiently in sub loop (dumb mistake). but now i am interested in finding a better way of doing this since it has peaked my interest. SSS, Is this an undocumented method or is it standard practice? |
| ||
Why not check against the gadget handle instead of the name? Just like images, sounds and meshes, gadgets have a handle number.Type checkbox Field hnd End Type For i=1 to 5 chk.checkbox = new checkbox chk\hnd = CreateButton(.......) Next Function FindChecked.checkbox() ; This function returns a chk type reference so you can use it like... ; chk.checkbox = FindChecked() For chk.checkbox = each checkbox If ButtonState(chk\hnd) = 1 Return chk End If Next End Function |
| ||
The speed of the comparision isnt any faster. The function still needs to iterate through the loop. I was hoping for something a bit more in the flavor of a native function. i might use SSS's method dealing with the handles is a good idea, but i need more of a human interface. By this i mean a method that a developer can use tofind a checkbox by using the name, since the developer is not going to know the handle id right off the bat. Thanks for the help though. Very much appreciated |
| ||
well the developer could know the handle right off the bat if you did something like thistype Button field x,y .... end type function CreateButton(...) b.Button = new Button ;set the parameters return Handle(b) end function function FindButton.Button(hButton) b.Button = Object.Button(hButton) return b end function |
| ||
ahh.. there we go... thanks SSS. |