FG Spreadshirt Swag
  1. #1

    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)?

  2. #2
    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.

  3. #3
    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 .

  4. #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....

  5. #5
    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

  6. #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.

  7. #7
    Quote Originally Posted by joshuha
    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).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in