PDA

View Full Version : Crosslinking between extensions



MooCow
January 14th, 2020, 00:30
I've made two extensions now, and I've also made an icon that I only want displayed if both of these extensions have been loaded at the same time.
(It's an button_roll icon graphic for the Kult ruleset, with a Ghost Theme background.)
Randomly surfing around on the internet, just randomly clicking at links to Fantasy Grounds sites that show up on the first hit page, "reveals" that there doesn't seem to be any onLoaded() function to keep track of what extensions are loaded into a session, but I've seen that instances can be checked for the existence of tags, by scripts inside templates, so there might be some "if exists" condition in a script, that could be able to either check the existence of another script, or the image to use itself.

Something like this, would be nice:


onDesktopInit()
if exists extension Ghost
<includefile source="crosslink/ghostkult.xml" />
end
end


First I thought that all extensions would share the same virtual folder structure, and that I could therefor just put "<includefile source="crosslink/kult.xml" />" into the initiation file of Kult, and "crosslink/kult.xml" (containing the merging instructions) in Ghost, but then FG refused to load Kult because it couldn't find the file to include, and this despite of it being present in Ghost. I don't know if changing the load order for Ghost would change anything, but I doubt it.

...so is there any way to do this sort of conditional "only if extension/ruleset is present" merge?

LordEntrails
January 14th, 2020, 01:55
Not sure if this would help, but the DOE extensions use a function/capability that requires the DOE Base to be loaded before any of the other extensions will work. Might give you what you are looking for.

MooCow
January 14th, 2020, 02:55
Not sure if this would help, but the DOE extensions use a function/capability that requires the DOE Base to be loaded before any of the other extensions will work. Might give you what you are looking for.

Isn't that just done with a <dependency> tag? I don't want the entire extension to fail. I want them both to work individually without problems, but when they work together, something extra also happens. That's a little more complicated.

While I was randomly looking around for tags just now, I happened to stumble onto a function called "getExtensions()", which apparently retrieves a list of names of loaded extensions. "A list" sounds complicated to script a retrieval from, but might be what I'm looking for.

The problem with that is that not even Moon Wizard knows how that works:

Make sure you are using pairs() and not ipairs() to interate over table. The rulesetdepencies table is ("string" -> table ("minrelease"="MIN", "maxrelease"="MAX"), "string" -> ...)
It's the same for "extensiondependencies".
Exclusion groups are a way to prevent more than one type of a given extension from loading (i.e. Themes), though it's not really used in practive. That data should be under "exclusiongroups".
Try a Debug.console(getExtensionInfo(s)) to review the full output.
NOTE: I did not have a change to build out code to double-check all of this; so let me know if it's not working as expected.
...and it didn't work for some reason, and Moon Wizard never got back to him, so I guess it's all a mystery for tomorrow, once I've slept. (I wonder what "pairs()" is.) Also there's "[DEV] Added Extension.getExtensions and Extension.getExtensionInfo functions (similar to Module functions)", so I might also want to find out what a "module" is.

If I'm really lucky I'll even find how to use it in the DOE extension that you mentioned. (I'll do a word search and hope for the best.)

This thread also talks how to do the syntax for identifying extensions loaded based on their unique script names, but that sounds like a much less elegant solution:
https://www.fantasygrounds.com/forums/showthread.php?51246-Load-order-of-extensions/page2

At least I've got plenty of leads now. Just gotta sleep now, so that I can think. :)

dulux-oz
January 14th, 2020, 03:21
Damned was on the right track. What you need is my custom fpIsExtensionLoaded() function, which I now give you permission to use (everyone else: please ask before using) - I am still retaining all Copyright to this :)



fpIsExtensionLoaded()

sExtensionName = The name of the extension you are trying to determine is loaded or not.
Returns TRUE if the extension is loaded, FALSE if otherwise.


function fpIsExtensionLoaded(sExtensionName)
for kKey,vValue in pairs(Extension.getExtensions()) do
if string.find(sExtensionName,vValue) then
return true;
end
end
return false
end


So, that'll need to go ito one or both of your Extensions, and if TRUE, display your icon.

Hope that helps

Cheers

MooCow
January 14th, 2020, 13:32
Damned was on the right track. What you need is my custom fpIsExtensionLoaded() function, which I now give you permission to use (everyone else: please ask before using) - I am still retaining all Copyright to this :)


fpIsExtensionLoaded()
sExtensionName = The name of the extension you are trying to determine is loaded or not.
Returns TRUE if the extension is loaded, FALSE if otherwise.
fpIsExtensionLoaded(sExtensionName)
for nIndex,sName in pairs(Extension.getExtensions()) do
if string.find(sName,sExtensionName) then
return true;
end
end
return false
end

So, that'll need to go ito one or both of your Extensions, and if TRUE, display your icon.
Hope that helps
Cheers

Thank you! This is exactly what I was looking for.
However, from a technical standpoint, picking an entry from a list, is so fundamental that I doubt you're able to claim a copyright for it. I'm pretty sure that the creator of lua would object.

dulux-oz
January 15th, 2020, 02:16
Thank you! This is exactly what I was looking for.
However, from a technical standpoint, picking an entry from a list, is so fundamental that I doubt you're able to claim a copyright for it. I'm pretty sure that the creator of lua would object.

Actually, I can, am, and will continue to claim Copyright on the implementation of that piece of logic, as per the relevant (Australian & International) Copyright Law.

I take Copyright very seriously, both on my own code and on using others', as I deal with Copyright issues at a senior level regularly.

Anyway, I hope that piece of code helps you with your extensions. :)

Cheers

Oberoten
January 15th, 2020, 02:41
Damned was on the right track. What you need is my custom fpIsExtensionLoaded() function, which I now give you permission to use (everyone else: please ask before using) - I am still retaining all Copyright to this :)



fpIsExtensionLoaded()

sExtensionName = The name of the extension you are trying to determine is loaded or not.
Returns TRUE if the extension is loaded, FALSE if otherwise.


fpIsExtensionLoaded(sExtensionName)
for nIndex,sName in pairs(Extension.getExtensions()) do
if string.find(sName,sExtensionName) then
return true;
end
end
return false
end


So, that'll need to go ito one or both of your Extensions, and if TRUE, display your icon.

Hope that helps

Cheers

This is brilliant Dulux. Could I use? I will of course as always retain copyright notices and credit where due.

- Obe

MooCow
January 15th, 2020, 03:28
Actually, I can, am, and will continue to claim Copyright on the implementation of that piece of logic, as per the relevant (Australian & International) Copyright Law.
I take Copyright very seriously, both on my own code and on using others', as I deal with Copyright issues at a senior level regularly.
Anyway, I hope that piece of code helps you with your extensions. :)
Cheers

Since your draconian measures are trying to restrict people from using basic script functionality on this platform, I'd like to challenge your copyright claim, but I don't have to. I don't have to implement your code as-is. I just have to learn the syntax used in it, and then use that syntax to make my own code, since it happens to have a different purpose. ...but legally, and variable names aside, you're not the first person to have used that data retrieval routine, so if there's any copyright what-so-ever, it belongs to one of the hundreds of writers before you.

dulux-oz
January 15th, 2020, 10:13
This is brilliant Dulux. Could I use? I will of course as always retain copyright notices and credit where due.

- Obe

Yes Obe, you can use the function, not a problem - I'm always willing to help out people who are polite :)

dulux-oz
January 15th, 2020, 10:37
Since your draconian measures are trying to restrict people from using basic script functionality on this platform, I'd like to challenge your copyright claim, but I don't have to. I don't have to implement your code as-is. I just have to learn the syntax used in it, and then use that syntax to make my own code, since it happens to have a different purpose. ...but legally, and variable names aside, you're not the first person to have used that data retrieval routine, so if there's any copyright what-so-ever, it belongs to one of the hundreds of writers before you.

You can characterise my "measures" as you wish, up and to the point where you liable me (at which point I hope you are or know a very good lawyer) - and, yes, you certainly can take the ideas expressed in that piece of code and create your own implementation - but the implementation I provided to you - which I didn't have to - and free of charge - *IS* Copyrightable under all relevant Law and I am expressing my Copyrights as such.

I didn't say you couldn't use it - in fact, I put no restrictions on your use of it at all, except to express my rights. I've even said other can use it, and asked them to ask me first; this is just common courtesy and one of the principles of this community: Ask before using someone else's code.

But this is what I get for helping someone new to this Community out: accusations of "draconian measures" designed to "restrict people from using basic script functionality on this platform". Well, let me tell you something: there's a reason my Reputation on this site is as high as it is. It's because I provide all sorts of code, simple and advanced, plus Extensions and Rulesets, to this Community, most of it for free. *ALL* of it is Copyrightable, and all of it is useful to my fellow Devs and general FG Users alike. I've gone out of my way to be a useful, helpful member of this Community, and the Community has responded with thanks, praise, Reputation, and kudos - my record stands for itself.

So don't bother asking me for help (directly or indirectly) in the future, because you won't get it. Why should I help a rude, inconsiderate, "newbie" who doesn't know when to accept a gift that is given to him?!

Don't bother replying - I won't be answering.

[EDIT: Remove content that could inflame situation even though it was not intended that way.]