PDA

View Full Version : Stuck, Can't count the skill ranks



Meliora
September 28th, 2007, 20:29
Hi all,

I surrender with this. I'm certain this is possible, but I just can't figure it out.

How do I set up a script, that calculate the sum of all the player's ranks in skills, so I can post that total in a box on the skill page (code mainly based on the D20 ruleset)?

GoOrange
September 30th, 2007, 16:00
You could just set up a function that looks up the skill ranks in the DB and then adds them all up.

The ranks are all recorded in the database with a structure along the lines of "skillist.id-00009.ranks". I think the base d20 ruleset has 36 skills to you could use a brute force method of writing a function line that adds *.id-00001.* +*.id-00002.* all the way up to 36.

You might get into a problem if things are set up like the default d20 ruleset where you can add new skills with the radial menu, or add multiple knowledge skills. If this is the case, you'll need to come up with a function to determine if the DB node exists (like does skill #37 exist), and then if it does to look up the ranks and add them to the total.

That's how I would approach it in theory.

Meliora
September 30th, 2007, 16:46
I actually just got it...was getting in here to say so, and that I will try to cover it in a tutorial...it is somehow the same way as you suggest. I used days on it now, and all it takes is a little bit of coding...but I got it. Yeah, me :D.

Hamish
September 30th, 2007, 17:15
I needed to access all skills a little while back. The thing I did (kudos to Joshuha) is use the getChildren("skilllist") method to return a table of objects that refer to the skills, then cycle through them using "for k, o in ipairs(table)".

If you need more help, let me know....

Meliora
September 30th, 2007, 17:25
Thanks...I got it now. This script will do it:

local points = 0;

for k, v in pairs(window.skilllist.getDatabaseNode().getChildr en()) do
if v.getChild("ranks") then
points = points + v.getChild("ranks").getValue();
end
end
setValue(points);
end

joshuha
September 30th, 2007, 21:26
Do you have this tied into an onChildUpdate handler that points to the skillist node? It's a neat way to make it auto-update if any of the skill ranks are updated.

Meliora
October 2nd, 2007, 13:39
Do you have this tied into an onChildUpdate handler that points to the skillist node? It's a neat way to make it auto-update if any of the skill ranks are updated.

I will try to see if I can finish another of my noob tutorial here soon and I will show how I did it (which I couldn't have done without all the help on this forum). It is called on an update (actually the submit button).