PDA

View Full Version : Modifierstack.lua



Paul Pratt
April 8th, 2010, 22:47
In the code for modifierstack.lua how can I get the value of an individual slot?

slots.number returns nil

slots.description works so I figured I was in the right direction.

I am trying to set the modifier stack to pass a roll/keep situation.

I drag an attribute number (say strength) to the stack, then a skill to the stack. I want to roll the sum and keep the attribute in dice. So far it works in a /die command, works if I set to directly to a specific customdie, but to find the true value to keep, I need the slots.number value and convert that to a custom die.

I hope I made sense, I am way too many hours awake on this one!

Any idea how to get the slots.number value?

Foen
April 9th, 2010, 06:30
You need to iterate over each slot in the stack (from 1 to #slots) and then pull out slot[i].number:


for i=1,#slots do
num = slots[i].number;
--[[ do something with num ]]
end

Hope that helps

Foen

Paul Pratt
April 9th, 2010, 08:08
Thank you, Foen. I was working with for i=1, #slots do

but using num = slots[i].number moved this right along.

Too many hours, too many "if's" dancing in my head.

Thank you again,

Paul

Paul Pratt
April 9th, 2010, 18:43
Here is what I have so far. It works, just seems there must be a better way to state this.
When you double click an ability or skill it sends it to the modstack, then as long as the ability was the last thing sent to the stack it makes a proper roll keep, otherwise it sends of a sum of d4's.

So, far so good. I can live with that while I work on the roll/keep not depending on custom die.

I wish I could set this up so it evalutes to a proper roll clicking in any order, but that is beyond me. I can have it evalute a specific slot using slots[x].desc or number, using [i] always returns the last thing clicked.

Any thoughts out there?


function getKeep()
local keep;
for i =1, #slots do
local num = slots[i].number;
local desc = slots[i].description;
if desc == "Brawn" then
if num == 1 then
keep = "k1"
elseif num == 2 then
keep = "k2"
elseif num == 3 then
keep = "k3"
elseif num == 4 then
keep = "k4"
elseif num == 5 then
keep = "k5"
elseif num == 6 then
keep = "k6"
elseif num == 7 then
keep = "k7"
end
elseif desc == "Finesse" then
if num == 1 then
keep = "k1"
elseif num == 2 then
keep = "k2"
elseif num == 3 then
keep = "k3"
elseif num == 4 then
keep = "k4"
elseif num == 5 then
keep = "k5"
elseif num == 6 then
keep = "k6"
elseif num == 7 then
keep = "k7"
end
-- code repeated for the other abilites as above
else
keep = "d4"
end
end
return keep;
end

Foen
April 9th, 2010, 19:13
I don't know what system you are trying to automate (and I don't recognise it from the code) so find it a bit difficult to understand the question.

There are certainly ways to make that code more 'neat' such as:


if desc == "Brawn" then
if num == 1 then
keep = "k1"
elseif num == 2 then
keep = "k2"
elseif num == 3 then
keep = "k3"
elseif num == 4 then
keep = "k4"
elseif num == 5 then
keep = "k5"
elseif num == 6 then
keep = "k6"
elseif num == 7 then
keep = "k7"
end
elseif...

Becomes:


if desc == "Brawn" then
if num > 0 and num < 8 then
keep = "k"..num
end
elseif...

Hope that helps a bit

Foen

Paul Pratt
April 9th, 2010, 19:24
That is a much better statement. Thank you.

Well, what I am attempting to do is take the modstack you designed for WoD and use that to pass a roll/keep dielist instead of a the WoD 'success' dielist.

So, far so good. I just find my coding abilities are lacking, and some of the code is very poor and could be better stated. Your tips have been quite useful.

Manipulating the .xml to make a sheet look different is far easier than manipulating the die rolls. I may be in over my head, but the fun is in learning.

It works, so I can host my 7th Seas games soon. Just need to clean up some rough edges and figure out a few more die rolling bits to be complete.

Also, Foen, thank you for being so kind as to reply to a beginners questions. So far, each time I have posted you have been right there with a reply. I imagine it is very difficult to attempt to reply to code questions without seeing the entire scope, but your efforts supporting the community are tremendous. Thanks.

Foen
April 9th, 2010, 19:34
Thank you for your kind compliments :o

I don't know what roll/keep means, however, or what the k1 to k7 are supposed to do. It would be helpful to understand a bit more about what you'd like out of the code: if "Brawn" is included in the modstack somewhere, and there are also three other entries in whatever order, what would you like to see?

Cheers

Foen

Paul Pratt
April 9th, 2010, 20:23
7th Seas uses a roll/keep method. So, for instance, if a character had Wits 3 and History 4 they would make a History check by rolling 7 dice(skill + trait) and keep the best 3 dice(trait).

I set up custom dice k1 thru k10. Meaning Keep1, Keep2, etc.

I am using the WoD as a base and changing things. The dot work was perfect for 7th Seas, they also use dots to track skills/traits levels.

So, you double click X trait and then X skill and they are sent to the modstack. Using the throwDice function and passing the function getKeep from above, the custom dice are passed to the dielist instead of d10's. The result is something like this. 7k3 History +4, Wits +3 [result total]. Right now as you click on the character sheet you have to click the trait last or it doesn't work. (I added the else d4 bit so a bunch of wrong die fly across the screen as a clear indication I am wrong..lol).

I am trying to make it so, in any order clicked, the result is correct. I can not add a number modifier to get a 7k3+5 result. It will add the number as additional dice and make it 12k3. I know that is a feature for WoD.

So, I am in search of a work around for both those issues. Perhaps adding an additional modifier type box that only adds numbers not die and get the whole lot when the dice land in chat-chat.

Also, can the default dice be hidden? I'd love to show only d10's on the desktop, but so far, tinkering around in game elements using <invisible /> tags in the .xml does nothing.

Fun stuff, I just need to remember to play games once in a while and not just mod away...lol. Sort of like the ultimate puzzle and brain teaser for the inexperienced.

Paul