How to display player attributes as a fraction?

OK, hey again everyone! Thanks so much for your help on the day/night cycle problem!

This time I wanna know if it's possible to display player attributes as a fraction that you can change dynamically. For example, a Stamina meter. What I would like is for the Stamina meter to display as (Value)/100. The Value would change depending on what the player does, I.E. Attacking costs 5 Stamina, moving costs 3, ETC.

My guess is that the best way to do it would be to store the current Stamina as player.StamCurrent and the max as player.StamMax, then set the value of player.Stamina to (player.StamCurrent) / (player.StamMax)?
For example:

player.StamCurrent = 100
player.StamMax = 100
player.Stamina = player.StamCurrent / player.StamMax (This is what the player would see)

The only issue I see with this is that the fraction would simplify, causing 50/100 to appear as 1/2, and 100/100 to appear as 1. If this would even remotely work at all.

EDIT: While this is not the most graceful solution, until I can figure out a way to do it the way I originally wanted to do it this'll have to work.

While it's not graceful, it's pretty simple: Store the Max and Current values for the Stamina as different attributes that the player can see. So in the menu it would say:
Health: 100/100
Money: $40
Stamina: 100
Max Stamina: 100


Io

YES, it is possible!

First, your current method, and the way to PREVENT simplification.

You simply need player.Stamina to be a String attribute as opposed to a number. So you do:

player.Stamina=player.StamCurrent+"/"+player.StamMax

If StamCurrent=50 and player.StamMax=100, then it'll print out 50/100.

But what if you want to change the demoninator? What if you want to store, say, Stamina as being 0-100, but only want the player to see 0-50?

We introduce a new attribute, player.StamFractionSet, as a number. In short, player.StamFractionSet is set to whatever number you want the player to see as the 'StamMax'.

The code then becomes:

player.Stamina=(player.StamCurrent*(player.StamFractionSet/player.StamMax))+"/"+player.StamFractionSet

With a StamCurrent of 50, StamMax of 100, and StamFractionSet of 50, the player will then see 25/50.

Also, you can add the Stam and MaxStam attributes to the player as ones that are not visible, ie add them directly to the player Object, and not the 'player attributes' you see in the Game tab.

Hope this helps!


Thanks so much yet again for the help! I would definitely like to change the player's maximum Stamina at one point.


Io

Keep in mind that if you want to change the ACTUAL MaxStamina, then you'll also have to change the StamFractionSet appropriately.

Like, if MaxStamina goes from 100 to 98, then StamFractionSet has to go from 50 to 49.


(filler for getting this edited post, updated/posted)


just a bit of explanation:

player.StamCurrent = 100
player.StamMax = 100
player.Stamina = player.StamCurrent / player.StamMax

for your

player.Stamina = player.StamCurrent / player.StamMax

the 'player.Stamina' Attribute is an Integer Attribute:

player.Stamina = INTEGER_VALUE / INTEGER_VALUE

and, this is an Assignment Operation, so the FINAL VALUE (an Integer Value: int / int = int) gets STORED into the 'player.Stamina' Integer Attribute VARIABLE

also, you're doing a division operation, via the '/' symbol in it

which, is not what you wanted, as you want to keep the 'int / int' for displayment, but you're calculating (dividing) it instead, because you wrote/coded an Integer Attribute Assignment Operation


instead, you needed to code/write in a String Attribute Assignment Operation:

strings are NOT amounts, and only amounts can be calculated (math done on them), strings can't be calculated, but they can be concatenated (literally put together or rather put next to each other)

player.Stamina = player.StamCurrent + "/" + player.StamMax

now, this is a String Attribute (having TEXT and VARIABLE)

TEXT: "/" ------- this is NO longer a division operator, as it's now TEXT (a String Value), and so it's NOT a division operation, and also the use of the '+' symbols along with the TEXT, are concatenation (string) operations, telling quest that the Final Value is a String Value, and thus the Assignment VARIABLE is to be a String VARIABLE, making it a String VARIABLE Assignment Operation

VARIABLES: 'player.StamCurrent' and 'player.StamMax'

so, we're concatenating the VARIABLES and TEXT together:

(under the scenes, quest is powerful/smart with its parsing, and so, it is converting the Integer Values of the 'player.StamCurrent' and 'player.StamMax' into String Values, as the expression is a concatenation/string expression, so that's why the integer values are being converted under the scenes by quest for you, without you having to do it yourself, into string values)

[VARIABLE1] [TEXT] [VARIABLE2]
[player.StamCurrent] ["/"] [player.StamMax]

player.StamCurrent = 50
player.StamMax = 100

[50] ["/"] [100]
50 / 100

FINAL Value (a String Value): "50 / 100"

which the FINAL VALUE, then lastly gets STORED INTO the 'player.Stamina' String Attribute VARIABLE:

player.Stamina = player.StamCurrent + "/" + player.StamMax
// player.Stamina = [player.StamCurrent] ["/"] [player.StamMax]
// player.Stamina = [50] ["/"] [100]
// player.Stamina = "50 / 100"

Data/VARIABLE/Attribute/Value Types are extremely important!


Amount (can do math/calculations/arithmetic on them) Data Types:

integers (ints): ...,-999, -1, 0, 1, 999,...

doubles (double/floats/floating-points/decimals/fractions): ..., -999.123, -1.9999999999999, 0.0, 1.123, 999.1111111111111, ....


NON-AMOUNT (can NOT do math/calculations/arithmetic on them) Data Types:

Strings

Booleans

Object reference/pointers

Scripts

Lists

Dictionaries


quest is able to parse from the VALUE, what Data Type it is:

var = "hi" // the 'var' Variable VARIABLE is created as a String Variable, as its FINAL VALUE "hi" is a String Value

var = "hi" + ", my name is HK" + ", what is your name?" // the 'var' Variable VARIABLE is created as a String Variable, as its FINAL VALUE "hi, my name is HK, what is your name?" is a String Value

var = 5 // the 'var' Variable VARIABLE is created as a Integer Variable, as its FINAL VALUE '5' is an Integer Value

var = 5.5 // the 'var' Variable VARIABLE is created as a Double Variable, as its FINAL VALUE '5.5' is a Double Value

var = false // the 'var' Variable VARIABLE is created as a Boolean Variable, as its FINAL VALUE 'false' is a Boolean Value

var = true // the 'var' Variable VARIABLE is created as a Boolean Variable, as its FINAL VALUE 'true' is a Boolean Value

create ("katana")
var = katana // the 'var' Variable VARIABLE is created as an Object reference/pointer Variable, as its FINAL VALUE 'katana' is an Object reference/pointer Value

var = NewStringList () // the 'var' Variable VARIABLE is created as a Stringlist Variable, as its FINAL VALUE is a new/blank String List
list add (var, "red")
list add (var, "blue")
list add (var, "yellow")
DisplayList (var, true) // or (not sure on correct syntax): DisplayList (var, 1)
// displayment:
// 1. red
// 2. blue
// 3. yellow


but if you're creating/adding the Attributes through the GUI/Editor's 'Attribute' Tab... you need to make sure you're setting the correct Attribute Type for the usage that you're using it in

for example:

in the GUI/Editor:

add/create Object -> name: katana

'katana' Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

[Object Name: katana]
Attribute Name: damage
Attribute Type: string
Attribute Value: 50

and then in Scripting (such as in a Verb, like say 'attack'), you got this:

orc.current_life = orc.current_life - katana.damage

and the 'orc.current_life' is an Integer Attribute

then you'll get an error:

non-matching data type error:

INT = INT - STRING ---> ERROR: DOES NOT COMPUTE!

so, you got to be careful, and here's the correction/fix:

add/create Object -> name: katana

'katana' Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

[Object Name: katana]
Attribute Name: damage
Attribute Type: int <------- fix/correction is here (it was 'string', but now we changed it to 'int')
Attribute Value: 50

and then in Scripting (such as in a Verb, like say 'attack'), you got this:

orc.current_life = orc.current_life - katana.damage

and the 'orc.current_life' is an Integer Attribute

and now:

INT = INT - INT // NO error!


PS

if this just confuses you even more, ignore it, as I didn't realize it would be harder to explain than I thought it would, so I did a really bad job with it, and likely just confused you, so ignore this if it jsut confuses you more, sorry about this poor attempt at trying to explain this stuff.


Log in to post a reply.

Support

Forums