Thread Tools Display Modes
11-17-05, 03:26 AM   #1
briggsy
A Murloc Raider
Join Date: Nov 2005
Posts: 7
For Loop Question,

Hi i have a table of Data that is searched using an editbox, i have that working however, when i display the results in a For table i get the frst result spammed over and over, here is how my loop is setup.


Code:
function mymod_Update()

	local Item;

	FauxScrollFrame_Update(mymodScrollFrame, 40, 23, 16);
	for iItem = 1, 23, 1 do
		local Index = Item + FauxScrollFrame_GetOffset(mymodScrollFrame);
		local Name = getglobal("mymodbutton"..Item);
	


			Name:SetText(result);
			Name:Show();
		
	end
end
This results in my hole scrollframe spammed with the first result. not a list of results i had inteded.


i have never used loops before.
Help oO
  Reply With Quote
11-17-05, 03:37 AM   #2
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
Where is "result" defined? If result is a global variable then this line will put its value in every box:
Code:
Name:SetText(result);
If it's a local variable then you shouldn't see anything in the boxes.

Your for loop is structured fine. As a test you can do:

Name:SetText("line "..Item)

or

Name:SetText("line "..Index) -- will be more meaningful
  Reply With Quote
11-17-05, 04:20 AM   #3
briggsy
A Murloc Raider
Join Date: Nov 2005
Posts: 7
Yes, result is a global from another function that searches my data, this is strange, (im a noob) how do i display "Result" then? so it only displays the number of results i have.

Thank you for a swift responce.

Edit:

Ok i got the correct number of results to show, however im having a huge problem trying to make an array global.

(so "Result" displays more than one result.)

my Search has 2 results, 2 buttons are displayed in the ScrollFrame, the last Search result takes the name of all the buttons. i am trying to make the search results to show indevidualy.

Last edited by briggsy : 11-17-05 at 06:40 AM.
  Reply With Quote
11-17-05, 06:36 AM   #4
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
Whatever is calculating result needs to be in the loop. If you have this function:

local function make_result()
result = result + 1
end

Then

result = 0
for i=1,5 do
make_result()
DEFAULT_CHAT_FRAME:AddMessage(result)
end

prints:
1
2
3
4
5

I suspect you have something like:

result = 0
make_result()
for i=1,5 do
DEFAULT_CHAT_FRAME:AddMessage(result)
end

prints:
1
1
1
1
1
  Reply With Quote
11-18-05, 08:59 AM   #5
briggsy
A Murloc Raider
Join Date: Nov 2005
Posts: 7
i cant seem to call the function in my loop. if i do it almost crashes the game with a string overflow.

my Result function has its own loops to get the data from my source. ?(multipul search results)


im realy confused now, i have everything working but this.
  Reply With Quote
11-18-05, 11:25 AM   #6
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
Your mod wants to show a series of results in a scrollable list it looks like. It needs that list.

You may want to consider making a table that stores the results instead of calculating result on the fly. This will be *a lot* better performance-wise if it takes a lot to get a result. Every time the scroll thumb is moved all visible entries will need recalcuated if you don't.

edit: Bunch of stuff removed that will just confuse things I think. After rereading your posts it sounds like whatever makes "result" does something intensive. Can you post how "result" is created? Turning "result" into a list is the primary purpose of that function.

It's possible that it's something that shouldn't be done in a scroll frame update (which gets called a bazillion times). Does it target anything? Does it assist or switch gear or anything else that's intensive?

As an aside, to create an array/table/list (in lua they're all the same really):

Say this is a hypothetical function that defines "result" your global variable. (btw I strongly recommend making "result" local to the mod or changing the name. I know of two mods that also use "result", tho theirs are local)

Code:
function Do_Whatever_Calculates_Result()
	result = "Random test "..math.random(100)
end
To add 40 "result" to a list:

Code:
myList = {}
for Item=1,40 do
  Do_Whatever_Calculates_Result()
  table.insert(myList,result)
end
That will make a list that looks like:

myList = {
["1"] = "Random test 23",
["2"] = "Random test 83",
["3"] = "Random test 49",
...
["40"] = "Random test 12"
}

Last edited by Gello : 11-18-05 at 11:54 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » For Loop Question,


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off