-
June 16th, 2019, 00: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 04:24.
-
June 17th, 2019, 07: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, 15:22 #3
Supreme Deity
- Join Date
- May 2011
- Location
- Denver, Colorado, USA (for a bit)
- Posts
- 24,195
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 16:31. Reason: Clarity
FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
Register at www.fg-con.com for all the latest info.
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, 19:26 #4
-
June 17th, 2019, 20: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, 20:32 #6
Supreme Deity
- Join Date
- May 2011
- Location
- Denver, Colorado, USA (for a bit)
- Posts
- 24,195
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.htmlFG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
Register at www.fg-con.com for all the latest info.
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, 20:37 #7---
Coding the Official AD&D Ruleset
My Twitch Channel for AD&D and FG related streams (See schedule for live days)
My YouTube for FG related Tutorials and AD&D Actual Plays
-
June 17th, 2019, 20: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 muchI 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, 20:38 #9
-
June 17th, 2019, 20:46 #10
Supreme Deity
- Join Date
- May 2011
- Location
- Denver, Colorado, USA (for a bit)
- Posts
- 24,195
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.
FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
Register at www.fg-con.com for all the latest info.
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