Player selects number for player attribute
Laraqua
21 Mar 2018, 10:13I'd like to allow players to select the number of shooters and melee fighters they have in their party. At this stage something really simple like Add Shooter / Add Melee is fine as a command. However, both of those two options affect their attack, defence, damage scores differently. How can I make it so that instead of setting the variable player.defence to a set amount, it will increase by a certain amount depending on how many shooters or melee folks are picked?
In other words, if melee adds plus 1 defence and plus 1 damage, while firearms adds plus 1 to player.attack and plus 1 to player.damage, how do I write a Command that will stack these player.defence and player.damage rather than just setting the variable to a specific and static amount?
hegemonkhan
21 Mar 2018, 11:13in programming (unlike in math), there's the 'Assignment' operator/operation:
VARIABLE = VALUE_OR_EXPRESSION // NO error
the 'VALUE_OR_EXPRESSION' ON THE RIGHT SIDE OF THE ASSIGNMENT OPERATOR is STORED in the 'VARIABLE' ON THE LEFT SIDE OF THE ASSIGNMENT OPERATOR
VALUE_OR_EXPRESSION = VARIABLE // ERROR!
whereas, in math, you're actually using a comparison operation/operator ('equal to'), which unfortunately, often is not taught/explained to you in math classes, lol:
is the LEFT SIDE OF THE EQUAL-TO OPERATOR and the RIGHT SIDE OF THE EQUAL-TO OPERATOR, the same?
// is: n = 2?
// (NO error):
5n = 10
5 * (2) = 10
10 = 10
// yes, both sides are the same, so yes, n=2
// is: n = 2?
// (NO error):
10 = 5n
10 = 5 * (2)
10 = 10
// yes, both sides are the same, so yes, n=2
so, to just directly 'set' a Value for a VARIABLE:
player.strength = 0 // the 'player' Object's 'strength' Integer Attribute's 'Value' is now '0'
player.strength = 100 // the 'player' Object's 'strength' Integer Attribute's 'Value' is now '100'
player.strength = 50 // the 'player' Object's 'strength' Integer Attribute's 'Value' is now '50'
player.strength = 77 // the 'player' Object's 'strength' Integer Attribute's 'Value' is now '77'
player.strength = 22 // the 'player' Object's 'strength' Integer Attribute's 'Value' is now '22'
to do arithmetic (increase-increment/decrease-decrement):
player.strength = 0 // our initially 'set' value, for this example
Addition: +
// how it conceptually is working:
// old value: player.strength = 0
player.strength = player.strength + 5
// how it conceptually is working:
// player.strength (new) = player.strength (old: 0) + 5
// player.strength (new) = (0) + 5
// player.strength (new) = 5
// new value: player.strength = 5
// old value: player.strength = 5
player.strength = player.strength + 5
// how it conceptually is working:
// player.strength (new) = player.strength (old: 5) + 5
// player.strength (new) = (5) + 5
// player.strength (new) = 10
// new value: player.strength = 10
// old value: player.strength = 10
player.strength = player.strength + 5
// how it conceptually is working:
// player.strength (new) = player.strength (old: 10) + 5
// player.strength (new) = (10) + 5
// player.strength (new) = 15
// new value: player.strength = 15
etc etc etc
Addition: +
Subtraction: -
Multiplication: *
Division: /
Modulus (Division, but instead, it finds/gets/returns the REMAINDER): %
(programming has to do the integer calculations and decimal calculations separately, and then concatenate them back together, along with the dot/period in the correct location, using normalized scientific notation works best for it)
now, the 'EXPRESSION' part (remember: the 'VALUE_OR_EXPRESSION' HAS TO BE on the right side of the Assignment operator) works exactly like a math equation (order of operations, inner then outer, etc etc etc):
player.strength = player.strength + 5 // NO error
player.strength = 5 + player.strength // NO error
create ("katana")
katana.damage = 50
player.weapon = katana
player.strength = 50
player.damage = player.weapon.damage + player.weapon.damage * player.strength / 100
// the multiplication and division is done before the addition, just like in math, so...
// player.damage = 50 + 50 * 50 / 100
// player.damage = 50 + 50 * 1/2
// player.damage = 50 + 25
// player.damage = 75
player.damage = (player.weapon.damage + player.weapon.damage) * player.strength / 100
// now, the addition is done first, as the parenthesis (inner) takes priority over the outer (non-parenthesis), just like in math, so...
// player.damage = (50 + 50) * 50 / 100
// player.damage = 100 * 50 / 100
// player.damage = 100 * 1/2
// player.damage = 50
in quest's programming, the Assignment operator and the 'comparison (equal to)' operator are both: =
the difference is how/where the Expression is used:
player.strength = 100 // Assignment
player.strength = GetRandomInt (0,100) // Assignment again
if (player.strength = 100) { /* scripting */ } // Comparison (equal to)
// and within whatever other Scripts'/Functions' that are able to evaluate the expression/condition within its parenthesis
P.S.
within the 'GUI/Editor' the script options (increase/decrease object counter, or something like this) only do '+1' and '-1', so to do a different Value and/or different arithmetic operation, you need to choose the 'EXPRESSION' script option, which let's you type in the expression yourself:
an example (using 'x3'):
run as script -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)
set variable player.strength = [EXPRESSION] 1 // I don't know what the normal [XXX] is for it off hand (so, I'm just using the '{EXPRESSION]' again)... I don't use the GUI/Editor much... Anyways, this is setting it's initial value of '1', as if we used '0', the value would never be increased as this example is using multiplication (anything x 0 = 0), lol
run as script -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)
set variable player.strength = [EXPRESSION] player.strength * 3
hegemonkhan
21 Mar 2018, 11:33here's a more detailed guide:
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
(scroll down about half-way to 'THE TWO SUPER SCRIPTS' sections to get to Attribute and the 'if' Script usage, where I explain how to do arithmetic operations, and at the near the bottom of how to do transactions: buying/selling)
Laraqua
23 Mar 2018, 01:22Thanks!