Thread Tools Display Modes
10-19-06, 11:53 AM   #1
jon
A Defias Bandit
Join Date: Oct 2006
Posts: 3
Need help understanding this lua code

Hey, Ive been trying to understand the different functions in this lua for awhile now,

Can anyone break this down for me? My brain just cant handle it.

Thanks in advance, Jon


Code:
-- Author : Bitt (Alliance Rogue) on Jubei'Thos
--
-- Version 0.3 Date: 9 July 2006
--     Implemented an options dialog which allows toggling of whether the
--             delay time is adjusted for lag.
--     /cdo displays the Options dialog for Chat Delay.
--     Saves the state of the Lag Adjust selection between game sessions
--
-- Version 0.2 Date: 8 July 2006
--     Can be called as a slash command with comman separated arguments
--             EG: /cdel Five seconds have elapsed,5
--
-- Version 0.1 Date : 25 June 2006
--     Allows a message to be delayed by a number of seconds before being
--             sent using SAY
--     Adds 2 x latency to the chat delay

CDEL_VERSION = "0.3";
CDEL_OPTION_TEXT = "Options"
CDEL_LAG_OPTION_TEXT = "Lag Compensation"

function TimerActive()
	return cdelTimer == 1;
end

function cdel_EventHandler(event)
	if ( event == "VARIABLES_LOADED" ) then
		if ( not CdelOptions ) then
			CdelOptions = { };
			CdelOptions["LagAdjust"] = true;
		else
			cdel_options_load();
		end
	end
end

function cdel_splitLine(cmd,delim)
	-- Searches for 1st occurence of delim and splits the string at that point returning each part
	if not delim then
		delim = ',';
	end
	if cmd then
		local s,l,str = strfind(cmd,delim);
		if s then
			return strsub(cmd,1,l-1), strsub(cmd,l+1);
		else
			return cmd;
		end
	end
	return cmd;
end

function cdel_slashCall(cmd,func)
	-- calls func with upto 10 arguments
	local args = {};
	local i = 0;
	local j = 1;
	repeat
		args[i],args[j] = cdel_splitLine(cmd,',');
		cmd = args[j];
		i = i+1;
		j = j+1;
	until not cmd;
	func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[6],args[7],args[8],args[9]);
end

function cdel_load()
	SLASH_CDEL1 = "/cdel";
	SlashCmdList["CDEL"] = function(cmd)
		cdel_slashCall(cmd,cdel);
	end

	SLASH_CDO1 = "/cdo";
	SlashCmdList["CDO"] = cdel_opt;

	-- Initialise the timers
	cdel_initialize();
	this:RegisterEvent("VARIABLES_LOADED");
end

function cdel_options_load()
	if (CdelOptions) then
		CdelOptLagAdjust:SetChecked(CdelOptions["LagAdjust"]);
	end
end

function cdel_initialize()
	cdelOptVisible = 0;
	cdelTimer = 0;
	cdelStartTime = 0;
	cdelTimerFunc = doMsg;
end

function cdel_opt()
	if ( cdelOptVisible == 0 ) then
		cdelOptVisible = 1;
		CdelOptFrame:Show();
	else
		cdelOptVisible = 0;
		CdelOptFrame:Hide();
	end		
end

function Cdel_Opt_Lag_OnClick()
	if ( CdelOptions.LagAdjust ) then
		CdelOptions["LagAdjust"] = false;
	else
		CdelOptions["LagAdjust"] = true;
	end	
end

function cdel_credits()
    chat_frame_message("Chat Delay is loaded - version "..CDEL_VERSION);
end

function cdel_update_timer()
	local elapsed = getCdelElapsedTime();
	if ( elapsed >= cdelTimerDelay ) then
		cdel_initialize();
		cdelTimerFunc(cdelTimerArgs);
	end
end
    
function cdel_startTimer()
	cdelTimer = 1;
	cdelStartTime = time();
end

function chat_frame_message(msg)
    DEFAULT_CHAT_FRAME:AddMessage("|cff00f100"..msg);
end

function getCdelElapsedTime()
    return time() - cdelStartTime;
end

function cdel(msg,delay)
	if ( CdelOptions.LagAdjust ) then
		lag = GetNetStats();
	else
		lag = 0;
	end
	if not msg then
		return;
	end
	if msg and not delay then
		delay = 0;
	end
--	chat_frame_message("Lag: "..lag.." milliseconds."); 

	cdelTimerDelay = delay + (lag * 2);
	cdelTimerArgs = msg
	cdel_startTimer();
end

function doMsg(msg,delay)
	SendChatMessage(msg);
end
  Reply With Quote
10-19-06, 12:21 PM   #2
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
perhaps be more specific on what you need help with? Your post comes across as saying "Teach me Lua!" which frankly, no one wants to do.

I am sure there are plenty of us more than willing to help you understand things if you can tell us exactly what part you are having trouble understanding.
  Reply With Quote
10-19-06, 07:36 PM   #3
jon
A Defias Bandit
Join Date: Oct 2006
Posts: 3
What im trying to do is get this to delay a whisper instead of a /say.


Thanks again, Jon
  Reply With Quote
10-21-06, 05:13 AM   #4
Zeksie
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 24
Originally Posted by jon
What im trying to do is get this to delay a whisper instead of a /say.


Thanks again, Jon
http://www.wowwiki.com/API_SendChatMessage
  Reply With Quote
10-22-06, 11:14 PM   #5
jon
A Defias Bandit
Join Date: Oct 2006
Posts: 3
Originally Posted by Zeksie


Thank you!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need help understanding this lua code


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