Thread Tools Display Modes
04-06-16, 12:58 AM   #1
suipsyco
A Deviate Faerie Dragon
Join Date: Apr 2016
Posts: 13
basic function help

I'm sure I just have some simple syntax error, but I cant see it...

Code:
local tanks = {};

function FindTanks()
	for i = 1 .. 40 do
		local unit = "raid" .. i;
		if UnitGroupRolesAssigned(unit) == "TANK" 
		then table.add(tanks, unit) 
		end
	end
end
Incidentally, since the code won't run for me yet, I don't know that it will do what I want it to do. Anyone know if I'm on the right track? Goal is to loop through the raid and add all the players marked TANK into my list. Maybe there's a way to do this that I couldn't find. I just want a list of the tanks in the raid.
  Reply With Quote
04-06-16, 02:37 AM   #2
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
for i=1,40 do
__________________
"In this world nothing can be said to be certain, except that fractional reserve banking is a Ponzi scheme and that you won't believe it." - Mandrill
  Reply With Quote
04-06-16, 05:25 AM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Aside from the loop syntax, the function is table.insert, not table.add.

You also might want to add wipe(tanks) before your loop to clear out previous entries if this is going to be called repeatedly to avoid inserting the same units multiple times or keeping stale data around.

If you have lua errors enabled in-game (which you should do if you're writing an addon), they'll tell you what line the problem is on, which should help you work out what's causing it.

Last edited by semlar : 04-06-16 at 05:29 AM.
  Reply With Quote
04-06-16, 10:56 AM   #4
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
You also might want to install BugGrabber and BugSack.
Both are usefull to detect and handle lua errors.
__________________
Better to fail then never have tried at all.
  Reply With Quote
04-06-16, 11:33 AM   #5
suipsyco
A Deviate Faerie Dragon
Join Date: Apr 2016
Posts: 13
Thank you all I will make the changes and install bug grabber. The blizzard Lua Error grabber just told me a "." expected near do, which wasn't helping
  Reply With Quote
04-06-16, 12:19 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Originally Posted by suipsyco View Post
Thank you all I will make the changes and install bug grabber.
You will need BugSack (or Bugger) as well.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-06-16, 12:29 PM   #7
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by suipsyco View Post
Thank you all I will make the changes and install bug grabber. The blizzard Lua Error grabber just told me a "." expected near do, which wasn't helping
I can see how that error might not seem helpful when you're not used to this stuff, but it's actually spot on! Installing a different error handler will not change the error message you receive, but it might present them in a better way, and store them for review later and stuff.

The error would have said "," expected (comma, not a period) near "do". If we review the code:
Code:
for i = 1 .. 40 do
".." joins the two values (1 and 40) together so there's only one value here. A second value and a comma separating them was expected, hence the error. Actually it's not entirely obvious what the error means, I suppose, since a comma alone would not have made it work, but it's always (I think?) helpful in pinpointing where exactly the interpreter has trouble making sense of your code. Which isn't necessarily in the same place that you need to fix something. Errors mentioning "end"s and parentheses may be due to a missing or extra parenthesis somewhere else.
__________________
Grab your sword and fight the Horde!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » basic function help

Thread Tools
Display Modes

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