PDA

View Full Version : help with Lua



Dragon_of_old
August 7th, 2016, 02:33
Hello everyone

I’m trying to build a custom ruleset for a game system I want to run. I have it how I want it to look, but I know nothing about “Lua”, so I’m keeping it very, very simple, so for right now I just want to write script that takes five values and adds them together to make a sixth value at is the total of the other five. I’ve done a little with Javascript but that is it.

So like stat A is “1”, stat B is “2”, stat C is “4”, armor stat is “1”, race stat is “2” and finally comes out in the Total stat as “10” it keeps an eye on it so if a play change a stat it updates.

This is what I have tried
function onInit()

STATa = statA.getValue();
STATb = statB.getValue();
STATc = statC.getValue();
ARMmod = armMod.getValue();
RACEmod = raceMod.getValue();

totA = (STATa + STATb);
totB = (STATc + ARMmod);
totC = (totB + RACEmod);

total.setValue(totC);
end
If there is a better way to do this, I am all ears.

Talyn
August 7th, 2016, 03:05
I used to do Lua scripting back in the World of Warcraft 1.x days -- 2004-2006 but haven't touched it since then.

The main site for the Lua scripting language is lua.org (https://www.lua.org/) and documentation manuals are there. I believe the current Fantasy Grounds engine contains Lua 5.1.

There's also still a #lua channel on Freenode IRC. It was very busy back when I was doing the WoW addons but I don't know how busy it is today.

But generally, have the 5.1 manual handy and read other people's Lua scripts to figure out what they're doing.

damned
August 7th, 2016, 04:03
Welcome Dragon_of_old
Your best bet is to look at an existing example.
Have a look at the 3.5e or 4e or 5e ruleset where they calculate AC for example as that takes multiple value - base+dex+armour+other

Dragon_of_old
August 7th, 2016, 04:42
Thank I'll give that a try

Trenloe
August 7th, 2016, 16:06
If you're displaying this in a number field then you can use the <op> functionality to add a few fields together. See the example at the top of this page: https://www.fantasygrounds.com/modguide/templates.xcp

And also discussed in this thread: https://www.fantasygrounds.com/forums/showthread.php?33368-Help-Simple-Number-Counter

Dragon_of_old
August 7th, 2016, 17:15
forgot about that I'll give it a try thank.