Paul Pratt
February 6th, 2020, 22:32
Hello,
While working on Warhammer 2e, I ran into an interesting issue that I eventually solved, but that solution seems to be a rather labor intensive and frankly novice way to handle things. I am a hobbyist, I have no real practical skill in coding and when iterating over tables I find my self in the deep end of the pool with no flotation device. I am hoping someone within the community can show me a pro way of handling this.
In Warhammer, players can make casting roll checks to cast spells. They have a Magic characteristic, and this governs how many d10's they throw when making the test. The practical amount of d10's that can be thrown would be 1d10 up to 7d10. So, I have 1-7d10's to handle. The roll itself is simple, throw the amount of d10's desired and beat a target number. That works as intended and I have no issues with. After throwing the dice, the results of the dice can trigger a further series of events called Manifestations. Basically think of it as magical "fumbles". The results of the casting roll are evaluated and any pairs, triples or quadruples, or combinations of those are tallied. They are labeled - pairs (Minor), triples (Major), quadruples (Catastrophic).
For instance, if someone rolls 4d10 and the results are {2,5,5,2} - that would mean 2 Minor (pairs) Manifestations result from the cast.
I need to take the table aDice.Result and find all the possible combinations of pairs, triple, quadruples, then report the amount of Minor, Major, and Catastrophic results.
I solved it by using this basic format and extending it out from 2 die to 7 dice and all the combinations of results, i.e. when rolling 4d10 I had to cover Catastrophic, Major, Minor, and two Minor. Obviously the more dice the more complicated this became, with some entries being hundreds of comparisons.
Three dice rolled and checking for a triple:
elseif nRoll == 3 then
local nDie1 = rRoll.aDice[1].result;
local nDie2 = rRoll.aDice[2].result;
local nDie3 = rRoll.aDice[3].result;
if (nDie1 == nDie2) and (nDie1 == nDie3) then
if bArcane == "Arcane" then
rMessage.text = rMessage.text .. "\r TZEENTCH's CURSE! \r Major Manifestation";
I have entries with 310 possible combinations when checking 7 dice for multiple pairs. I know there has to be a better way. I long handed it, it works, it may have errors though. I know I have the correct amount of combinations for each of my entries, I could do the math to make sure of that, but the potential for typos and hunting them down is enormous.
Just looking to learn something here, so any help is appreciated.
While working on Warhammer 2e, I ran into an interesting issue that I eventually solved, but that solution seems to be a rather labor intensive and frankly novice way to handle things. I am a hobbyist, I have no real practical skill in coding and when iterating over tables I find my self in the deep end of the pool with no flotation device. I am hoping someone within the community can show me a pro way of handling this.
In Warhammer, players can make casting roll checks to cast spells. They have a Magic characteristic, and this governs how many d10's they throw when making the test. The practical amount of d10's that can be thrown would be 1d10 up to 7d10. So, I have 1-7d10's to handle. The roll itself is simple, throw the amount of d10's desired and beat a target number. That works as intended and I have no issues with. After throwing the dice, the results of the dice can trigger a further series of events called Manifestations. Basically think of it as magical "fumbles". The results of the casting roll are evaluated and any pairs, triples or quadruples, or combinations of those are tallied. They are labeled - pairs (Minor), triples (Major), quadruples (Catastrophic).
For instance, if someone rolls 4d10 and the results are {2,5,5,2} - that would mean 2 Minor (pairs) Manifestations result from the cast.
I need to take the table aDice.Result and find all the possible combinations of pairs, triple, quadruples, then report the amount of Minor, Major, and Catastrophic results.
I solved it by using this basic format and extending it out from 2 die to 7 dice and all the combinations of results, i.e. when rolling 4d10 I had to cover Catastrophic, Major, Minor, and two Minor. Obviously the more dice the more complicated this became, with some entries being hundreds of comparisons.
Three dice rolled and checking for a triple:
elseif nRoll == 3 then
local nDie1 = rRoll.aDice[1].result;
local nDie2 = rRoll.aDice[2].result;
local nDie3 = rRoll.aDice[3].result;
if (nDie1 == nDie2) and (nDie1 == nDie3) then
if bArcane == "Arcane" then
rMessage.text = rMessage.text .. "\r TZEENTCH's CURSE! \r Major Manifestation";
I have entries with 310 possible combinations when checking 7 dice for multiple pairs. I know there has to be a better way. I long handed it, it works, it may have errors though. I know I have the correct amount of combinations for each of my entries, I could do the math to make sure of that, but the potential for typos and hunting them down is enormous.
Just looking to learn something here, so any help is appreciated.