-
September 28th, 2007, 20:29 #1
- Join Date
- Sep 2007
- Posts
- 38
Stuck, Can't count the skill ranks
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)?
-
September 30th, 2007, 16:00 #2
- Join Date
- Jun 2007
- Location
- Central NY
- Posts
- 151
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.
-
September 30th, 2007, 16:46 #3
- Join Date
- Sep 2007
- Posts
- 38
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 .
-
September 30th, 2007, 17:15 #4
- Join Date
- Jun 2007
- Location
- Zeist, Netherlands
- Posts
- 286
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....
-
September 30th, 2007, 17:25 #5
- Join Date
- Sep 2007
- Posts
- 38
Thanks...I got it now. This script will do it:
Code:local points = 0; for k, v in pairs(window.skilllist.getDatabaseNode().getChildren()) do if v.getChild("ranks") then points = points + v.getChild("ranks").getValue(); end end setValue(points); end
-
September 30th, 2007, 21:26 #6
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.
-
October 2nd, 2007, 13:39 #7
- Join Date
- Sep 2007
- Posts
- 38
Originally Posted by joshuha
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks