View Single Post
  #1  
Unread 09-28-2010, 06:48 AM
lerusius lerusius is offline
The Wary
 
Join Date: Sep 2010
Posts: 3
Beginners LUA Problem: Calling function located in another file

Hello! I'm a real beginner in Lua and programming. But I'd like to learn so here goes my first question!

I want to when I use /bs getsize to return the size of all bags you currently have unlocked. but I get the error
"...\Main.lua:16 : Attempting to index global 'BagspaceLeftFunction' (a nil value)"

I have marked line 16 with blue.

What I'm trying to do is to use the function BagspaceLeftFunction:BagSize() that is located in another file. Any ideas how to fix this?

_init_.lua
Code:
-- Common imports.
import "Turbine";
import "Turbine.Gameplay";
import "Turbine.UI";
import "Turbine.UI.Extensions";
import "Turbine.UI.Lotro";
import "Turbine.Utils";

--BagspaceLeft specific
import "Lerusius.BagspaceLeft.BagspaceLeft";
Main.lua
Code:
--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:BagSize();
	elseif (arguments == "help") then
		Turbine.Shell.WriteLine(self:GetHelp());
	end
end

--Welcome Message when loading the plugin
Turbine.Shell.WriteLine("BagspaceLeft by Lerusius");
BagspaceLeft.lua
Code:
function BagspaceLeftFunction:BagSize()
	local player = Turbine.Gameplay.LocalPlayer();
	self.backpack = player:GetBackpack();
	Turbine.Shell.WriteLine (self.backpack:GetSize());
end
Reply With Quote