-
June 15th, 2019, 23:45 #1
Adding new die to existing dice collection
Hi
I now learned how to code a trigger for dice rolls with their chat message etc., in my case a d100 triggered by an effect. However, the problem is that the number of d100 is arbitrary in my code (so, it can be that it has to be 2d100 instead of just d100) and that depends on the situation, like a DMG effect can add an additional die to the damage in 3.5e. I do not know how to add additional d100 to the existing one, I tried table.insert like I saw it in the coding of the DMG effect but that does somehow not work. To break down my code I try at some point in my code:
Code:local bDice = {}; bDice = table.insert(bDice, {"d100, d10"});
Do I use the insert function somehow wrong? I tried to do it similar to other parts in existing code but something is going wrong here for me
Best,
Kelrugem
EDIT: Oh, of course, bDice will be the variable defining the type of die of my roll, so it will be in some "rRoll" and rRoll.aDice = bDice (following the guideline in the comments at the very top of manager_actions.lua in CoreRPG).Last edited by Kelrugem; June 16th, 2019 at 03:24.
-
June 17th, 2019, 06:58 #2
To explain a bit more: When I look at bDice before table.insert (by using Debug.console(bDice)) then it returns the defined value, but after table.insert it is empty. So, e.g.
Code:local bDice = {"d100", "d10"}; bDice = table.insert(bDice, {"d100, d10"});
-
June 17th, 2019, 14:22 #3
Looks like you’re trying to insert a table into a table, whereas (in theory) this should work as far as LUA is concerned, it won't give the correct format for FG. In FG code I haven't seen multiple dice added at once. Try inserting the d100 and d10 separately as two table.insert commands.
Last edited by Trenloe; June 17th, 2019 at 15:31. Reason: Clarity
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
June 17th, 2019, 18:26 #4
-
June 17th, 2019, 19:28 #5
Ok, now I was trying
Code:bDice = table.insert(bDice, "d100"); bDice = table.insert(bDice, "d10");
Script Error: [string "scripts/manager_action_damage.lua"]:517: bad argument #1 to 'insert' (table expected, got nil)
-
June 17th, 2019, 19:32 #6
That's because you're overwriting bDice in the first line with the result of the table.insert function, which I don't think returns anything. This is the first issue you had in your original post - sorry I didn't spot that too, I was more looking at inserting a table into a table being an issue.
Define bDice as an empty table first, then just use table.insert...
Details here: https://www.lua.org/pil/19.2.htmlPrivate Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
June 17th, 2019, 19:37 #7---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset FGU Reference Module, or Web.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
June 17th, 2019, 19:38 #8
aaaaaah, okay, now I see it Oh, I was trying so much and I also found that page from your link but I never saw the difference... So table.insert is a function returning already the cahnged bDice For some reasons I thought I have to designate/name that return still for calling it later (therefore the "bDice=..." in front)
Thank you very much I should have asked earlier, could have saved me a lot of time Now I wonder how I couldn't see that because table.insert is also used that way in the existing code
-
June 17th, 2019, 19:38 #9
-
June 17th, 2019, 19:46 #10
If you always want bDice to be a d100 and a d10 then you can just statically set the table as you did in the first line of post #2: local bDice = {"d100", "d10"}; Then you can add any further dice to this as required using one table.insert for each die to be added.
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks