Page 1 of 2
Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:01 pm
by NutJob
I have this function...
Code: Select all
function grantPuzzleExp(totalExp)
local c = nil; local p = party.party; local a = {}; local exp = 0;
for i=1, 4 do
c = p:getChampion(i)
if c:getEnabled() and c:isAlive() then table.insert(a,i) end
end
exp = math.ceil(totalExp / #a)
for _,n in ipairs(a) do
p:getChampion(n):gainExp(exp)
end
end
...I would like to access without having to put it in every single script_entity when I want to use it.
How do I make a library that all scripts can access so I can call my generic functions?
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:14 pm
by jxjxjf
I'm by no means a lua expert, but the way I've been doing this is by calling the function through the name of the script entity.
So, if you had that function in a script entity named "expScript", you'd call it like:
expScript.script:grantPuzzleExp(100);
It's ugly, but it works for me. haha
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:16 pm
by NutJob
I'll give it a try. Thank you very much. Having that script in 12 script_entities seems like a waste when I can just do an include or import of a file or something.
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:20 pm
by jxjxjf
Yeah, it sort of defeats the purpose of writing a beautiful function in the first place. haha
Hope it works out.

Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:22 pm
by NutJob
It sort of works. The function runs without error but the parameter (the experience integer) does not get passed along.
Edit: the function now thinks the 'totalExp' is a table. Stumped. ~shrugs~
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:30 pm
by jxjxjf
Yeah, you're right... I've been doing this without parameters. Just tried it and integers don't pass, and a string will crash the whole thing.
I knew it was ugly, but I had hoped it would work for you. Sorry.
Hopefully someone else can give a real response.
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:32 pm
by NutJob
No worries, appreciate the insight on doing like this, in the first place. ~cheers~
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:52 pm
by Batty
You should search the LoG1 modding forum, many of these scripting issues are dealt with there.
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 4:59 pm
by SnowyOwl47
I got it guys! Because i've already done this many times in the Easy Scripts in my Basic Scripting reference its easy for me.
Make a script named whatever but ill call mine game,
make a function like you have:
Code: Select all
function grantPuzzleExp(totalExp)
local c = nil; local p = party.party; local a = {}; local exp = 0;
for i=1, 4 do
c = p:getChampion(i)
if c:getEnabled() and c:isAlive() then table.insert(a,i) end
end
exp = math.ceil(totalExp / #a)
for _,n in ipairs(a) do
p:getChampion(n):gainExp(exp)
end
end
And if you set it up correctly sense the scrip is named game you simply say
When making your own methods and code you can use globally you never put : never: ever: ever: its all dots .......
IF YOU EVER PLACE : instead of a dot . you it doesn't happen no errors but the grantPuzzleItem function won't get called because you don't use :
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 5:02 pm
by SnowyOwl47
Batty wrote:You should search the LoG1 modding forum, many of these scripting issues are dealt with there.
Log1 is way different then log2 so it wouldn't be a help he'd have to figure out how to convert it.