lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
Thread Tools Display Modes
  #1  
Unread 08-23-2011, 07:32 AM
Elsee Elsee is offline
The Wary
 
Join Date: Aug 2011
Posts: 3
Send a message via Skype™ to Elsee
Begginers Woe.

Hi there wanna get started writing a plugin and i cant get this to work, and i cant understand why.

Main.Lua
Code:
-- Main.lua
import "Elsees.Elsees.HelloClass";

ElseesCommand = Tubine.ShellCommand();
Tubine.Shell.AddCommand("el", ElseesCommand);

HelloClass class = HelloClass();

function ElseesCommand:Execute(cmd, args)
	if(cmd == "sayhi") then
		class.SayHello();
	else
		Turbine.Shell.WriteLine("Invalid Command");
        end
end

Tubine.Shell.WriteLine("Elsee Plugin V0.1");
HelloClass.lua
Code:
-- HelloClass
import "Turbine.Utils";
HelloClass = class( );

function HelloClass:Constructor()
	self.SayHello();
end

function HelloClass:SayHello()
	Turbine.Shell.WriteLine("Hello World!");
end
I have the Turbine Files in my plugin folder, all i get is the error "Unable to load Plugins "Elsees"", which i dont understand. from what i have googled that error was/is caused by bad directory structure?

Code:
LOTRO / Plugins / Elsees / Elsees / luafiles
Reply With Quote
  #2  
Unread 08-23-2011, 09:57 AM
Equendil Equendil is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Apr 2011
Posts: 52
Quote:
Originally Posted by Elsee
I have the Turbine Files in my plugin folder, all i get is the error "Unable to load Plugins "Elsees"", which i dont understand. from what i have googled that error was/is caused by bad directory structure?

Code:
LOTRO / Plugins / Elsees / Elsees / luafiles
or caused by a missing or invalid ".plugin" definition file, which you didn't show here.

Also possibly caused by adding/editing a ".plugin" file while the game is running without a "/plugins refresh".
__________________
Author of LIP, Bootstrap and Baruk
Reply With Quote
  #3  
Unread 08-23-2011, 10:19 AM
Elsee Elsee is offline
The Wary
 
Join Date: Aug 2011
Posts: 3
Send a message via Skype™ to Elsee
hey thanks for the reply. i do have a plugins file and it works, but only IF i dont use the HelloClass.lua

Elsees.plugin
Code:
<?xml version="1.0"?>
<Plugin>
    <Information>
        <Name>Elsees</Name>
        <Author>Elsee</Author>
        <Version>0.12</Version>
    </Information>
    <Package>Elsees.Elsees.Main</Package>
    <!--<Configuration Apartment="Plugin">
    </Configuration>-->
</Plugin>
this is located at :

Code:
LOTRO/ Plugins / Elsees / Elsees.plugin
Reply With Quote
  #4  
Unread 08-23-2011, 11:44 AM
Equendil Equendil is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Apr 2011
Posts: 52
Alright, a few more things here:

- If a plugin is already loaded, trying to load it again will fail. A plugin is considered loaded by the system if it was able to run its 'package' file without error (even if there are subsequent errors from events). Always make sure your plugin is not actually loaded when you get the "unable to load" error ("/plugins list" or equivalent through a plugin manager).

- You do not declare types in lua, "HelloClass class = HelloClass();" should be "class = HelloClass();". On a side note, and for the sake of nitpicking it's generally a bad idea to use a keyword as a variable name. While "class" is not a keyword of lua as such, it should probably be considered as such to avoid confusion since it's the name of the class factory provided by Turbine. Also what you get when you call "HelloClass()" is an "instance" or "object" of the class HelloClass, so it's semantically incorrect.

- Building a function using the colon notation is a syntaxic shortcut.

Declaring : "function HelloClass:SayHello()"
is equivalent to : HelloClass.SayHello = function( self )

if you then want to call that function as a "method" on an instance, you need to call it using the colon notation:
if your instance is called myHelloClass then you would call SayHello that way : myHelloClass:SayHello();
which is equivalent to : myHelloClass.SayHello( myHelloClass );

In your code, you should have "self:SayHello()" (in HelloClass.lua) and "class:SayHello()" (in main.lua).

- The "cmd" argument given to the Execute() method of a command is the name through which it was called (you can declare multiple names in Turbine.Shell.AddCommand(), if you separate them with ";"). You declared "el" as a name, so "cmd" will always be "el". If as I expect you want "/el sayhi" to result in the "Hello World!" message being sent to the console, you need to test "args", not "cmd".

All but the first point however, should either cause an error other than "unable to load plugin" or not cause an error.

Edit: Also nitpicking, you should declare your command fully before you export it to the system through Turbine.Shell.AddCommand(). If AddCommand() tested (I don't think it does) for the existence of an "Execute()" method on your command, it wouldn't find one.

Can't see anything else that would be wrong, structure seems alright to me, not got the game running to check everything else is fine though.
__________________
Author of LIP, Bootstrap and Baruk

Last edited by Equendil : 08-23-2011 at 11:53 AM.
Reply With Quote
  #5  
Unread 08-23-2011, 12:03 PM
Equendil Equendil is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Apr 2011
Posts: 52
While I'm at it, the most recent Turbine package (http://forums.lotro.com/showthread.p...amples-updated!) does not have a "Turbine.Utils" folder. Class.lua etc are found under "Turbine".
__________________
Author of LIP, Bootstrap and Baruk
Reply With Quote
  #6  
Unread 08-23-2011, 08:00 PM
Elsee Elsee is offline
The Wary
 
Join Date: Aug 2011
Posts: 3
Send a message via Skype™ to Elsee
Equendil .. you are awesome cheers will look into it

Im new to Lua as a language, but not programming so a few of this mistakes made me ./faceplam. but hey, we learn

Will get back to you soon.
Reply With Quote
Reply


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
Forum Jump


All times are GMT -5. The time now is 11:11 AM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui