PDA

View Full Version : Startup of a mod(lua code)


plastrader
28-10-2006, 06:16 PM
Hello,
I'm confused, maybe a bit "nubish", I've read the material @www.wowwiki.com
But I can't really get this together.

Which comes first of:
VARIABLES_LOADED
ADDON_LOADED

In my world ADDON_LOADED is the first thing that happens.
But, it seems functions/methods like:
GetRealmName()
UnitName("player")

and etc can't be "set" in either of ADDON_LOADED or VARIABLES_LOADED.

for example
If I put

function handle_addonload()
sendPrint(format("Hello %s from %s",UnitName("player"),GetRealmName()));
end
function sendPrint(string)
DEFAULT_CHAT_FRAME:AddMessage(string);
end


I get a script error.
Saying "error format, expected string, got nil"
I also get a script error while placing it in my "handle_varloaded()" function.

And not to mention what happens with variables when I do /console reloadui
it seems that variables set in the "header"(class variables) like
local myChecker=false;

is emtpy when I do /console reloadui.

Please help my confused brain.

dafire
28-10-2006, 07:25 PM
i think the player is not yet in the world when those events fire... there should be an event for that :)

plastrader
29-10-2006, 04:07 PM
Thanks again for your input dafire.

I did some investigations.

Class variables in top of my file.

local ModVersion = "v.0.10";
local myBoolean = false;
local myServer = GetRealmName();
local myFaction = UnitFactionGroup("player");
local myName, myRealm = UnitName("player");

..
then example event addon_loaded

if( (event=="ADDON_LOADED") and (arg1=="myMod") ) then
if(ModVersion=="v.0.10")then
ChatFrame3:AddMessage("AL: ModVersion=set correctly");
else
ChatFrame3:AddMessage("AL: ModVersion=not set!");
end
if(myBoolean==false or myBoolean)then
ChatFrame3:AddMessage("AL: myBoolean=set correctly");
else
ChatFrame3:AddMessage("AL: myBoolean=not set!");
end
if(myServer~=nil)then
ChatFrame3:AddMessage(format("AL: Server=%s",myServer));
else
myServer = "null";
ChatFrame3:AddMessage(format("AL: Server=%s",myServer));
end
if(myFaction~=nil)then
ChatFrame3:AddMessage(format("AL: Faction=%s",myFaction));
else
myFaction = "null";
ChatFrame3:AddMessage(format("AL: Faction=%s",myFaction));
end
if(myName~=nil)then
ChatFrame3:AddMessage(format("AL: Name=%s",myName));
else
myName = "null";
ChatFrame3:AddMessage(format("AL: Name=%s(s2=%s)",myName, myRealm));
end
if(myRealm~=nil)then
ChatFrame3:AddMessage(format("AL: Realm2=%s",myRealm));
else
myRealm = "null";
ChatFrame3:AddMessage(format("AL: Realm2=%s",myRealm));
end
if(UnitFactionGroup("player")~=nil)then
ChatFrame3:AddMessage(format("PE: UnitFactionGroup('player')=%s",UnitFactionGroup("player")));
else
ChatFrame3:AddMessage("PE: UnitFactionGroup('player')=null");
end
end


I have the similar if, else statments in
Variables loaded(VL)
Player entering world(PE)
events

When I log in first time I get:
AL: ModVersion=set correctly
AL: myBoolean=set correctly
AL: Server=<My current server>
AL: Faction=null
AL: Name=<My name>
AL: Realm2=null
AL: UnitFactionGroup('player')=null
**I had to change from " to ' because of errors in the code, the command is still: UnitFactionGroup("player");

I do "/console reloadui" i get:
AL: ModVersion=set correctly
AL: myBoolean=set correctly
AL: Server=<My current server>
AL: Faction=<My faction>
AL: Name=<My name>
AL: Realm2=null
AL: UnitFactionGroup('player')=<My faction>

However in the Player entering world event:
then "if(UnitFactionGroup("player")~=nil)then" returned
PE: UnitFactionGroup('player')=<My faction>

both in first load and "/console reloadui"

The command:
local myName, myRealm = UnitName("player");
seems not to return 2 values.

aspinkorgall
30-10-2006, 02:13 AM
The command:
local myName, myRealm = UnitName("player");
seems not to return 2 values.


As I recall that command only returns the server name in Battlegrounds?