Quantcast LoTROInterface - View Single Post - Beginners LUA Problem: Calling function located in another file
View Single Post
  #2  
Unread 09-28-2010, 11:23 AM
rushl rushl is offline
The Indomitable
Interface Author - Click to view interfaces
 
Join Date: Jun 2009
Posts: 14
I did something similar for Horsey. I ran your test code, and found a few changes that should get you going. First, none of the imports in your common file are reaching the later scripts. So I removed it altogether.

For your Main.lua, I ended up with:

Code:
import "Lerusius.BagspaceLeft.BagspaceLeft";

--Just for clarification on what I'm doing, changing name on
--the Turbine.Shell Command() to BSCommand
BSCommand = Turbine.ShellCommand();

--Could put this inside the Execute function but decided on having
--it here instead take a look at line 18 on how I'm using it
function BSCommand:GetHelp()
	return "This is the Help Command"
end

--adds the commands /bs or /bagspaceleft to lotro
Turbine.Shell.AddCommand("bs:bagspaceleft",BSCommand);

--Here comes the real adding of commands to the plugin. for example
--"/bs bagsize" will call the command BagspaceLeft:BagSize() that lies in
--BagspaceLeft.lua
function BSCommand:Execute( command, arguments)
	if (arguments=="getsize") then
		BagspaceLeftFunction();
	elseif (arguments == "help") then
		Turbine.Shell.WriteLine(self:GetHelp());
	end
end

--Welcome Message when loading the plugin
Turbine.Shell.WriteLine("BagspaceLeft by Lerusius");
Changes in yellow. I moved the function include here, and the function call name didn't need the index.

For your BagspaceLeft.lua:

Code:
import "Turbine.Gameplay";

function BagspaceLeftFunction()
	local player = Turbine.Gameplay.LocalPlayer();
	local backpack = player:GetBackpack();
	Turbine.Shell.WriteLine (backpack:GetSize());
end
Here I moved the Turbine.Gameplay import to this script. Also, I changed the now shortened BagspaceLeftFunction() name. Finally, the self.backpack index won't work here, so it's now a local variable too.

Running that, I get a return of "75" when I enter /bs getsize!

Hope this helps!

rushl

Last edited by rushl : 09-28-2010 at 11:42 AM.
Reply With Quote