Page 2 of 2
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 5:08 pm
by jxjxjf
SnowyOwl47 wrote: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 :
Beautiful. haha
This was starting to be one of those puzzles I needed to figure out before I could do anything else with my life. I'm still a lua novice.

Thank you so much.
I'm curious, though, what was actually happening, because the function
was being called with ':', just any passed parameters were going haywire.
EDIT: Nevermind, I looked it up and apparently ':' sends self as a parameter implicitly. The more you know.

Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 5:13 pm
by NutJob
Works. Nice work, thanks SnowyOwl47.
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 5:24 pm
by SnowyOwl47
No problem guys! Need any more help look at my easy commands in the basic scripting reference post.
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 5:27 pm
by NutJob
SnowyOwl47 wrote:No problem guys! Need any more help look at my easy commands in the basic scripting reference post.
:

:
...so, do you work for Staples? ~chuckles~
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 5:28 pm
by SnowyOwl47
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 8:26 pm
by JKos
It's possible to assign the library script to a script variable:
mylibrary script entity
Code: Select all
function myFunction(arg)
print(arg,'is nice')
end
...other functions...
Using library in another script
myscript
Code: Select all
--assign library to a script variable
lib = mylibrary.script
function youCanCallMeAtRunTime()
lib.myFunction("test")
end
-- this won't work, because it's "init time"
-- lib.myFunction("test")
This doesn't work on initialize time, which means you have to call myscript. youCanCallMeAtRunTime() after all scripts are loaded,
but you can for example spawn a pressure plate at the party starting location which calls myscript.youCanCAllMeAtRunTime().
It's a bit hacky but works, and we had to do similar hacks with LoG1 also, so nothing new here
WARNING: I did't test the save game compatibility of this solution. For example it's totally possible that the serializer duplicates all assigned scripts, which will cause problems with library variables.
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 9:56 pm
by JKos
I just tested the save game compatibility and it doesn't work, just gives an error when saving the game. So just forget my previous post.
It will be so awkward to type something.script.method() every time

, I hope AH provides some solution for this. But of course we will get used to extra ".script" too if nothing can be done.
Re: Library, Globally Accessible Functions
Posted: Fri Oct 24, 2014 10:21 pm
by NutJob
JKos wrote:I just tested the save game compatibility and it doesn't work, just gives an error when saving the game. So just forget my previous post.
It will be so awkward to type something.script.method() every time

, I hope AH provides some solution for this. But of course we will get used to extra ".script" too if nothing can be done.
Thanks for the heads up. I just need to remember when to use a method call or field call now. Convoluted!