PDA

View Full Version : Begginers Woe.


Elsee
08-23-2011, 07:32 AM
Hi there :) wanna get started writing a plugin and i cant get this to work, and i cant understand why.

Main.Lua

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

-- 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?


LOTRO / Plugins / Elsees / Elsees / luafiles

Equendil
08-23-2011, 09:57 AM
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?


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".

Elsee
08-23-2011, 10:19 AM
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

<?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 :


LOTRO/ Plugins / Elsees / Elsees.plugin

Equendil
08-23-2011, 11:44 AM
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.

Equendil
08-23-2011, 12:03 PM
While I'm at it, the most recent Turbine package (http://forums.lotro.com/showthread.php?370084-Documentation-and-examples-updated!) does not have a "Turbine.Utils" folder. Class.lua etc are found under "Turbine".

Elsee
08-23-2011, 08:00 PM
Equendil .. you are awesome :D 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 :D

Will get back to you soon.