PDA

View Full Version : How Powerful is Scripting in Fantasy Grounds



seansps
July 30th, 2020, 14:48
Hey everyone,

I was looking into how scripting works in Fantasy Grounds, looks like it uses LUA. I also found this reference here https://www.fantasygrounds.com/refdoc/.

As a developer myself I was wondering if I could create an extension that, using a certain package or list of assets, can randomly generate a a basic outdoor battle-mat. For instance, say you have an assets folder for backgrounds (plains, forest, swamp, tundra) and for each a folder of random assets for "doodads" (trees, terrain, etc.) Conceivably, a script would then:

- Create a map for the chosen background
- Set the grid to be 'on'
- Sprinkle an amount of doodads in the map based on another variable
- If possible, include LOS data for each doodad (but I think this would probably be... very difficult or impossible, since LOS data is per map)

I was looking to see if something like this already exists, but, I did not see anything, so I wanted to see if it's even possible with FG. Does anyone with experience in making extensions/mods for FG know if there is enough flexibility with the platform to do this?

LordEntrails
July 30th, 2020, 14:56
Nothing like this already exists.

You would not be able to do this in FGC, since maps are single image files. I suspect it is technically possible in FGU, but no one has yet said they have tried. So their may be some LUA call or such that is not exposed. Note I have seen the devs expose specific LUA calls/functions when other community devs have requested such.

As for LOS, that should be one of the easier parts, because FGU tile assets can already include LOS data with them, so if you can access and call the assets to build your image from, you should be able to include the LOS data.

seansps
July 30th, 2020, 15:01
Thanks for the reply! That's actually good to hear that the part I thought would be hardest is probably actually easiest.

But yes, if I looked into doing this, it would be in FGU. It'll take me some getting used to LUA but I think I could figure it out. I would love to spend some time looking into how maps are currently created/stored by FGU to try to see if it is possible. Perhaps this weekend I can do some digging around to see what calls may be needed.

I think an extension like this would be pretty awesome to go along with random encounters.

LordEntrails
July 30th, 2020, 15:03
It certainly would be pretty awesome :)

I'm sure some of the experienced community devs will be along today to give more insightful comments. I haven't done much with FG and and have far more experience writing software requirements than actually implementing them :)

Mytherus
July 30th, 2020, 15:50
If you accomplished this i would exalt your name among great extension devs!

As a DM i love this idea.

Trenloe
July 30th, 2020, 16:09
This gives an example of the imagecontrol API:

https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4162245/imagecontrol

This doesn't look like it has anything new specifically for FGU. I'm guessing that they haven't finalised the FGU image API yet. Hopefully there will be API calls added that will allow you to do what you mentioned in the OP.

seansps
July 30th, 2020, 17:45
This gives an example of the imagecontrol API:

https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4162245/imagecontrol

This doesn't look like it has anything new specifically for FGU. I'm guessing that they haven't finalised the FGU image API yet. Hopefully there will be API calls added that will allow you to do what you mentioned in the OP.

Awesome, thanks for this! And yeah, I definitely want to investigate this more. I'm hoping I can spend some time this weekend to get familiar with the API.

bmos
July 30th, 2020, 18:01
Just a heads up, that refdoc you linked is for FG Classic.
The Unity refdoc is much better and is here:
https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4096100/Developer+Guide

Special interest:
https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/269451327/Making+an+Asset+Pack+Tiles+Symbols+Brushes+Decorat ions
https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/260440084/Developer+Guide+-+Extracting+LOS+Data+for+Modules

seansps
July 30th, 2020, 18:03
Thanks! I'll look through that one later instead ;)

seansps
July 31st, 2020, 20:45
I'm making good progress with, at least, learning how to do things in custom extensions. I have a custom button added to the "Maps" window that creates an Image under a "Maps - Generated" category. Now I am running into a couple issues. (If there is a better forum to post this please let me know!)

- [FIXED] When I set the name of the image (using "image.setValue") it shows on the UI, but it doesn't save to the DB (and reverts to the default name on reload.)
- I haven't figured out how to add layers to the image... is this documented somewhere, or do I need to do it manually with `createChild` and `setValue` ?

Edit: I actually FIXED the first above by checking how images are currently structured in the db.xml. Still can't get layers working though.

Myrdin Potter
July 31st, 2020, 21:40
I'm making good progress with, at least, learning how to do things in custom extensions. I have a custom button added to the "Maps" window that creates an Image under a "Maps - Generated" category. Now I am running into a couple issues. (If there is a better forum to post this please let me know!)

- When I set the name of the image (using "image.setValue") it shows on the UI, but it doesn't save to the DB (and reverts to the default name on reload.)
- I haven't figured out how to add layers to the image... is this documented somewhere, or do I need to do it manually with `createChild` and `setValue` ?

Armory sub-form is where the programming people tend to hang out.

seansps
July 31st, 2020, 21:41
Thanks, I'll try there!