Skill buy/point allocation

I currently have a series of questions whose answers predetermine a set of skills (simply integer attributes). For example, a particular question asks how the player would break into a compound- if they chose sneak it, they naturally get a bonus to sneak (kinda old school Bethesda style).
However, I would like to be able to have points the player can assign to skills, both later on during level up and at the start of the game, in case they don't like the predetermined skills. How would I do that?

I know how to do it, I just don't know how to go about doing it. There would be a variable (pointsAvailable) equal to say 45. The player can use a command to set the stat to a certain value. After doing so, have a script compare the original value to the previous value, and add or subtract points from pointsAvailable appropriately. At the end of every allocation, compare the change in value to points available, and if the change in value is less than or equal to the pointsAvailable, the allocation goes through. That doesn't seem to be the best way to do this though, so I was wondering if someone else could think of another way to do it.

This is what I mean:

  1. Create a command, maybe "set 'skill' #numb#" that lets the player allocate points. (How to do this only during level up, Idk. The only way I can think of is to create an object on level up that the player can interact with as a verb to allocate points, and then destroy the object once the points are allocated.)
  2. Create 2 new attributes for the player: pointsAvailable and "skill"Previous. ("skill" is the name of the skill.) Skill previous is set equal to the skill's value at the start of the level up function.
  3. After the player runs the command, subtract skillPrevious from the skill's current value. If the result is positive, subtract that number from pointsAvailable if it is less than or equal to pointsAvailable. If it is negative, add the abs value of that number to pointsAvailable.

Thank you for any and all help, and forgive me if this is overly complicated and there is really just a simple solution.


from Jaynabonne's and Pixie's, 'levellib' (level library), not sure where to find it now, but here's my thread back when I was trying to learn it:

https://textadventures.co.uk/forum/quest/topic/5089/solved-level-library-pixies

(basically, you just do string manipulation with text processor commands, and bloody getting the syntax correct with it, in the Command Element or Function or Object_and_Script_Attribute_and_Delegate or whatever other scripting Element, along with creating additional Command Elements that do the 'increase' and 'decrease' functionality of your desired skill/stat point distribution/adjustment, via acting as buttons/hyperlinks that you can click on, along with handling the stat/skill points you got to work with and for each individual skill/stat adjustment/distribution or canceling/undoing it, so that you don't got beyond the upper limit allowed and/or lower than that skill/stat original/initial value, and any etc handling)

https://docs.textadventures.co.uk/quest/text_processor.html (the text processor commands)

ask if you need help on this stuff... (Edit: I understand this stuff much more easily now, just took a quick look over the code to get it, not rusty at it now, lol)


alternatively, you can probably create your own popup window frame with buttons/events, using the JS and html/css/etc-web programming, which KV, mrangel, and Pixie can probably help you with doing that stuff (I've still got to learn it too, sighs)


There is a tutorial:
http://docs.textadventures.co.uk/quest/ui-dialogue-points.html

It is one of the most complicated tutorials on there, and it is about creating a dialogue panel to handle it, which is not quite what you describe, so may not be so useful.


Thank you both for the help. I think Pixie's suggestion may be exactly what I need, after a bit of modification. I will confirm if that's the case after attempting it.


Didn't read Pixie's example... but,
I would do it this way...
"Congrads, you made a level! You now have 5 points to spend on your stats, you may add to:
{command:Strength} {command:Dexterity}… and so on."
If you can only increase a stat by 1 point per level, you could disable that choice from showing up again.


Well, I was able to get it to work. At the start of the game, players can now chose to assign points or have them assigned automatically by computer.
Now I have a similar problem. Upon level up, I would like to redisplay the attribute allocation menu so they can update it. Example: a player has 10 strength and they level up and are allowed to allocate one additional point. They chose to allocate it to strength, updating it from 10 to 11. When they level up again, they may chose to level strength up to 12.
I thought this would be relatively easy. On level up, take the players attribute and put it into a js var. In the attribute menu, the changes will affect the js var, which is then converted back into the player attribute. My problems are as such:

  1. I don't know how to assign a quest object attribute to a java variable (I did find a lot of "squiffy.get" which seemed like it could have been perfect).
  2. I can't seem to figure out how to print the variable to the screen.

DarkLizerd's solution would work and I'll use it if the js doesn't work, but I would prefer the js.


Edit: Made a silly mistake

  1. I don't know how to assign a quest object attribute to a java variable

If you just want a javascript variable, you can use something simple like:

JS.eval ("strengthstat = " + player.strength + ";")
That puts together a string like strengthstat = 14; and sends that string to the browser, to be executed as javascript.

  1. I can't seem to figure out how to print the variable to the screen.

Printing a JS variable is easy. You can just use the addText function in Javascript.

For example: addText ("Your strength is now "+strengthstat+".");
Or if you want it to scroll to make sure the player can see it, use addTextAndScroll instead.

But you probably don't want to.
In Pixie's example, it creates a HTML div to contain each of your stats (the line <div id="magic" style="display:inline;">0</div> in the example). So rather than printing a value, you most likely want to change the value that's already on the screen.

In the incAtt javascript function, it looks directly at the value on the page, instead of using a separate variable for it.

The javascript line n = parseInt($('#' + att).html()); finds the HTML element whose id is stored in the variable att, reads the HTML within that element, converts it to a number, and assigns that to the javascript variable n.

The line $('#' + att).html(n + 1); finds the HTML element whose id is in the variable att, and sets the text inside it to be the result of the expression n + 1.

So if you're using that, instead of setting a javascript variable to anything, you would have a piece of Quest code that looks something like:

foreach (stat, Split("strength;defense;magic;evasion")) {
  if (HasInt (player, stat)) {
    JS.eval ("$('#" + stat + "').text('" + GetAttribute (player, stat) + "');")
  }
}

running immediately after the dialog is displayed, to fill the dialog with the current values of your stats.


Well, it took me a long time (and a headache XD) but I figured out what you were saying, mrangel, and I was able to get it to work, so thank you.

Alas, the world is not nice to me. I hate asking for more help but I simply don't know enough about js to troubleshoot it. Using Pixie's dialogue box, I have discovered that if the dialogue box is opened more than once (i.e. Once during character creation and again on level up), the dialogue box freezes? I can't alter any of the values using the arrows and if I click "done" it will run the HandleDialogue function but the values are all default and the dialogue itself won't close. Again, sorry for asking for yet more help, and thank you all for your assistance and patience.


One way to keep someone from getting too strong, too quick, is to require more points to add stats as they increase...
(Assuming DnD normal 3-18)
1-5, .5 points to increase, IE +2 str for 1 point.
6-10, 1 point each.
10-15, 2 points each,
16, 3 points,
17, 4 points,
18, 5 points,
19, 7 points,
20, 9 points,
and so on...


Using Pixie's dialogue box, I have discovered that if the dialogue box is opened more than once

OK… I'm just skimming over the code, but it looks like you might be creating the dialogue box more than once. This could be a problem, because when you have 2 elements with the same ID, it doesn't know which to change.

My recommendation would be to make sure that the line:

JS.addText (GetFileData("dialogue.html"))

is only run once. Then when you want to display the dialog again, you would do:

JS.eval("$('#dialog_window_1').dialog('open');")

to make the hidden dialog reappear, rather than creating a new one.

The problem with this is that if the player loads a saved game, there won't be a hidden dialog to show.
So really, what you need to do is create the dialog in your UI initialisation script, and then open it whenever it's needed.

Does that make sense? I'm kind of rushed now so don't have time to explain in more depth, but if there's anything you need help with I'm sure someone will be around to answer.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums