View Single Post
11-01-10, 10:43 PM   #1
TransformedBG
A Fallenroot Satyr
Join Date: Oct 2010
Posts: 23
Functions for dummies?

So im a Noob not going to lie. And ive done the simple "hello world" file. Worked fine ect.

Now im just trying to get a little more in depth by doing simple yet not so simple things like functions. Im used to C++ where you make a prototype and a function call. And from what im understanding that kind of how .LUA and .XML work?

so heres what im trying:

GLUA.toc:
Code:
## Interface: 40000
## X-Curse-Packaged-Version: 1.0.0.1
## X-Curse-Project-Name: GLUA
## notes: this should spam a lvl up message in your guild chat stating that you have leveled up. It should call your class and lvl.

GLUA.xml
GLUA.lua
GLUA.lua
Code:
GLUA = {};
local GuildLevelUp = GLUA;

function GuildLevelUp.OnLoad(self) -- Loads on player login --
	self:RegesterEvent("PLAYER_LEVEL_UP");
	DEFAULT_CHAT_FRAME:AddMessage("[Scare Bears INC] Guild Level Up Announcer has been initialized!");
	DEFAULT_CHAT_FRAME:AddMessage(" Ver. 1.0.0.9");
	DEFAULT_CHAT_FRAME:AddMessage(" Currently there are no /commands.");
end

function GuildLevelUp.OnEvent(event) -- should process on event --
	local lvl = UnitLevel("player"); -- local variable that tells me what lvl the toon is --
	local race = UnitClass("player"); -- local variable that tells me what cls the toon is --
	if ( (event == "PLAYER_LEVEL_UP") ) then
		SendChatMessage("DING! Yeah thats right im now a level "..lvl.." "..race..".", "GUILD", nil, nil);
	end
end
GLUA.xml
Code:
<UI xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
	<Script file="GLUA.lua" />
	<Frame name ="GLUAFrame" hidden ="false">
		<Scripts>
			<OnLoad>GuildLevelUp.OnLoad(self);</OnLoad>
			<OnEvent>GuildLevelUp.OnEvent(event);</OnEvent>
		</Scripts>
	</Frame>
</UI>
Question 1:
Now from my understanding i shouldn't have to load GLUA.xml & GLUA.lua in the toc file just the GLUA.xml, because the <script file="glua.lua"/> should initialized the lua file?

Question 2:
Why doesnt my code work? lol am i missing a function or handler or something? Or do every program have to have a frame?

Question 3:
How would i write a test function and implement it in the game? ie i want to simulate a lvl up?

Not exactly sure what im doing. just have a generalized coding idea. I have been reading and just looking at examples. so this is kind of where i stand. Any help would be greatly appreciated.

Last edited by TransformedBG : 11-01-10 at 10:51 PM.
  Reply With Quote