Setting and Changing an Attributes Numeric Value

erekerendo
I am trying to give my character skill values and whatnot VIA the attributes section. It works. However I run into an issue when I try and have the attributes value increase by one

example: "player.agility + 1"

I suspect that this is because Quest does not see the numbers as numbers but as text. How do I fix this? An example I can copy, paste, and play with would be most helpful. Thank you.

The Pixie
Make sure you have set the attributes to be integers on the Attributes tab. The code to raise agaility would look like this in code:

player.agility = player.agility + 1


Here is a complete game that has player agility to 5 originally, adds one to it in the start script, then prints the result:

<!--Saved by Quest 5.6.5783.24153-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="agility">
<gameid>35b7d5c4-d5a2-4710-b86c-2e9741ad65a9</gameid>
<version>1.0</version>
<firstpublished>2016</firstpublished>
<start type="script">
player.agility = player.agility + 1
msg (player.agility)
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<agility type="int">5</agility>
</object>
</object>
</asl>

erekerendo
Thank you. I was typing "player.agility + 1" instead of "player.agility = player.agility + 1"

Lol, easy once I figured that out.

HegemonKhan
(if you already know some programming), I don't think quest has the ability to do:

player.agility += 1
// which is maybe what you were trying to do (if you already know some programming)

so you got to write out the full expression/statement in quest:

player.agility = player.agility OPERATOR Value

// Value: 1, or whatever you want
// OPERATOR: +, or whatever you want (subtraction: -, multiplication: *, quotient division: \, or remainder division: %)

----------

if you don't know programming, a quick lesson:

programming's Assignment Operator/Operation: =
is not the same as math's Equal Operator/Operation: =

(quest's) Programming's Assigment Operation:

Object_name.Attribute_name = Object_name.Attribute_name + Value_or_Expression

the result of the entire expression (the right side of the '=' symbol) is STORED/ASSIGNED INTO/TO the Attribute VARIABLE (on the left side of the '=' symbol)

whereas, as you know with math:

x = 10
y = x + 5
y = 15

x = 10
5 + x = y
y = 15

but, since when doing programming's assignment operation, for example:

1 + player.strength = player.strength ---> ERROR!
player.strength + 1 = player.strength ---> ERROR!

player.strength = player.strength + 1 ----> NO error
player.strength = 1 + player.strength ----> NO error

conceptual example of how it works:

initial (old) Value (shown as set/assigned to its Attribute VARIABLE): player.strength = 0
statement (Assignment Operation): player.strength = player.strength + 5
// value: 0
// Attribute (VARIABLE): player.strength
// expression (dynamic/variable addition operation): player.strength + 5

old value: player.strength = 0

player.strength (new) = player.strength (old: 0) + 5
player.strength (new) = (0) + 5 = 5

new value: player.strength = 5

old value: player.strength = 5

player.strength (new) = player.strength (old: 5) + 5
player.strength (new) = (5) + 5 = 10

new value: player.strength = 10

old value: player.strength = 10

player.strength (new) = player.strength (old: 10) + 5
player.strength (new) = (10) + 5 = 15

new value: player.strength = 15

old value: player.strength = 15

player.strength (new) = player.strength (old: 15) + 5
player.strength (new) = (15) + 5 = 20

new value: player.strength = 20

you get the idea...

------------

in quest, this is the terminology:

VARIABLES:
-> Variable // examples: result = Value_or_Expression, handled = Value_or_Expression // Variables are local in scope
-> Attribute // examples: player.strength = 100, game.greeting = "welcome to tron", orc.dead = false, orc.dead = true, HK.awesome = true
-> Parameter // (used with Functions and Commands)

----------

if you want/need more detail on Attributes (and the If Script):

viewtopic.php?f=18&t=5559

if you don't already know this stuff, lol

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

Support

Forums