Library, Globally Accessible Functions

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
jxjxjf
Posts: 33
Joined: Fri Oct 24, 2014 6:26 am

Re: Library, Globally Accessible Functions

Post 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. :D

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. :shock:
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Library, Globally Accessible Functions

Post by NutJob »

Works. Nice work, thanks SnowyOwl47.
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Library, Globally Accessible Functions

Post by SnowyOwl47 »

No problem guys! Need any more help look at my easy commands in the basic scripting reference post.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Library, Globally Accessible Functions

Post by NutJob »

SnowyOwl47 wrote:No problem guys! Need any more help look at my easy commands in the basic scripting reference post.
::thumbsup::

...so, do you work for Staples? ~chuckles~
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Library, Globally Accessible Functions

Post by SnowyOwl47 »

@NutJob LOL never I work for myself :lol:

but dat avatar :shock: :shock: :shock: :shock: :shock: :shock: :shock: :shock: :shock: :shock: HES WATCHING US!

Edit: I've also added the making a method/script in my advanced scripting.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Library, Globally Accessible Functions

Post 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.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Library, Globally Accessible Functions

Post 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 :roll:, I hope AH provides some solution for this. But of course we will get used to extra ".script" too if nothing can be done.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Library, Globally Accessible Functions

Post 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 :roll:, 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!
Post Reply