Any way to make a limit for an attribute so that it wouldn't rise/fall after a certain point?

coms77
16 Aug 2018, 18:41

Like, if I want to create a hunger stat for my character, how could I make the hunger stat not to fall below 0/above 100?


DarkLizerd
16 Aug 2018, 19:51

Simple...
if (player.hunger<0) {
player.hunger=0
}

if (player.hunger>100) {
player.hunger=100
}

Altho, Quest get confused when you use the "<" sometimes because that is part of a command structure.


coms77
16 Aug 2018, 20:22

Oh god, it was that simple. Thanks!


coms77
16 Aug 2018, 20:23

But where do I place the code? In the timer?


coms77
16 Aug 2018, 21:05

Never mind, I figured it out


mrangel
16 Aug 2018, 21:33

There's 2 ways you could do this. Either put it in the code every time you modify the hunger stat (the way you'd do it in most programming languages) or if you give the player object a script attribute named changedhunger, it will automatically be run every time their hunger attribute changes.


Curt A. P.
17 Aug 2018, 04:41

I used DarkLizerd's method and implemented it in a turnscript, which checks for all of the min/max stats.

mrangel, can you make a example with changedhunger, please?


hegemonkhan
17 Aug 2018, 06:26

@ Curt A.P.

(I'm not mrangel, but here's an example)

(when 'player.hunger_current' reaches 100, you die, you become 'dead', player.condition="dead", for this example)

(the 'player.hunger' String Attribute is merely for the displayment of 'CUR/MAX' hunger)

(in this code example of mine, the 'this' is the same as 'player', so within this post, you inter-exchange them)

(within the 'changedhunger_current' and 'changedhunger_maximum', the 'this.hunger = this.hunger_current + "/" this.hunger_maximum' is what updates the 'player.hunger', and then that new updated value/expression for the 'player.hunger', gets displayed by the 'player.statusattributes')

my example code's status pane (initial) displayment (and it'll update itself upon changing the Attributes' Values):

Hunger: 0/100
Condition: normal


<object name="player">

  <attr name="condition" type="string">normal</attr>

  <attr name="hunger" type="string">0/100</attr>

  <attr name="hunger_current" type="int">0</attr>

  <attr name="hunger_maximum" type="int">100</attr>

  <attr name="hunger_minimum" type="int">0</attr>

  <statusattributes type="stringdictionary">

    <item>
      <key>hunger</key>
      <value>Hunger: !</value>
    <item>

    <item>
      <key>condition</key>
      <value>Condition: !</value>
    <item>

  </statusattributes>

  <attr name="changedhunger_current" type="script">

    <![CDATA[

      if (this.hunger_current > this.hunger_maximum) {
        this.hunger_current = this.hunger_maximum
      } else if (this.hunger_current < this.hunger_minimum) {
        this.hunger_current = this.hunger_minimum
      }

      this.hunger = this.hunger_current + "/" + this.hunger_maximum

      if (this.hunger_current = this.hunger_maximum) {
        this.condition = "dead"
      }

    ]]>

  </attr>

  <attr name="changedhunger_maximum" type="script">

    <![CDATA[

      if (this.hunger_current > this.hunger_maximum) {
        this.hunger_current = this.hunger_maximum
      }

      this.hunger = this.hunger_current + "/" + this.hunger_maximum

    ]]>

  </attr>

</object>

Curt A. P.
22 Aug 2018, 21:28

@ hegemonkhan

Eh, this is tough... Sorry, I can't say I understand what's happening in this script, yet. Biggest problem is, I don't know what a script attribute is...


hegemonkhan
23 Aug 2018, 02:35

(filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)


.
.
@ Curt A.P.
.
.
here's how to do it step by step in the GUI/Editor:
.
(if you still need help, or need anything explained, let me know!)
.
.
(upon doing this in the GUI/Editor, it'll look the same in your entire game code view as seen in my post above, as doing this in the GUI/Editor, causes quest to do what I've done directly in code in my previous post, for you... but it's so much easier just doing it in code directly, lol.... once you understand coding... once I learned to code, I've not used the GUI/Editor ever since... lol. It's not too hard to learn to code in/with quest... and it makes, making your game, so much easier, so much faster, and you can do so much more cool stuff too)
.
.
(if my use of 'this.NAME_OF_ATTRIBUTE' is confusing you, you can, and if you do: you MUST, replace all of the code segments of 'this.NAME_OF_ATTRIBUTE' with 'player.NAME_OF_ATTRIBUTE', and also, you MUST NOT change the name of the 'player' Player Object, or if you want/need the 'player' Player Object to be a different name than 'player', then just replace all of the same code segments with 'NAME_OF_PLAYER_OBJECT.NAME_OF_ATTRIBUTE', and hopefully obviously, you replace all of my upper case stuff with what you're naming/calling them as, I hope it's obvious anyways, lol)
.
.

creating/setting the Attributes (and their initial Values):

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

the "normal" Attributes (String, Integer: int, Double, Boolean, Object reference/pointer, and Script Attributes):

(we're only using/creating 'String, Integer: int, and Script' Attributes for the "normal" Attributes of this code example)

'player' Player Object -> 'Attributes' Tab -> Attributes (box at the bottom) -> Add -> (see below, repeat as needed)

(Object Name: player)
Attribute Name: condition
Attribute Type: string
Attribute Value: normal

(Object Name: player)
Attribute Name: hunger
Attribute Type: string
Attribute Value: 0/100

(Object Name: player)
Attribute Name: hunger_current
Attribute Type: int // (int: integer)
Attribute Value: 0

(Object Name: player)
Attribute Name: hunger_minimum
Attribute Type: int // (int: integer)
Attribute Value: 0

(Object Name: player)
Attribute Name: hunger_maximum
Attribute Type: int // (int: integer)
Attribute Value: 100

(Object Name: player)
Attribute Name: changedhunger_current
Attribute Type: script
Attribute Value: (see below)

add new script -> 'scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] this.hunger_current > this.hunger_maximum

-> then -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable this.hunger_current = [EXPRESSION] this.hunger_maximum

else if [EXPRESSION] this.hunger_current < this.hunger_minimum

-> then -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable this.hunger_current = [EXPRESSION] this.hunger_minimum

add new script ->  'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable this.hunger = [EXPRESSION] this.hunger_current + "/" + this.hunger_maximum

add new script -> 'scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] this.hunger_current = this.hunger_maximum

-> then -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable this.condition = [EXPRESSION] "dead"

(Object Name: player)
Attribute Name: changedhunger_maximum
Attribute Type: script
Attribute Value: (see below)

add new script -> 'scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] this.hunger_current > this.hunger_maximum

-> then -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable this.hunger_current = [EXPRESSION] this.hunger_maximum

add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable this.hunger = [EXPRESSION] this.hunger_current + "/" + this.hunger_maximum

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

the "advanced" Attributes (List and Dictionary Attributes):

(we're only using/creating/over-riding/over-writing the built-in 'statusattributes' String Dictionary Attribute for the "advanced" Attributes in this code example)

'player' Player Object -> 'Attributes' Tab -> Status Attributes (box at the top) -> Add -> (see below, repeat as needed)

Item 1 of the built-in 'statusattributes' String Dictionary Attribute of/on (contained within) the 'player' Player Object:

(Object Name: player)
Item 1's 'Key' (its input value, as a String): (this is the 'Attribute Name' directly below)
Attribute Name: hunger
Item 1's 'Value' (its output value, as a String): (this is the 'Format String' directly below)
Format String: Hunger: !

item 2 of the built-in 'statusattributes' String Dictionary Attribute of/on (contained within) the 'player' Player Object:

(Object Name: player)
Item 2's 'Key' (its input value, as a String): (this is the 'Attribute Name' directly below)
Attribute Name: condition
Item 2's 'Value' (its output value, as a String): (this is the 'Format String' directly below)
Format String: Condition: !

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

Conceptually About:

List/Dictionary Attributes are literally just 'input-output' functionality !!!

List Attributes:

each item is automatically given its index number, starting at '0' (NOT 1 --- this takes awhile to get used to: index number vs the item number, for example: 7th item = 6 index number), and increases by 1 with each item

String List Attributes:

Item 1:
Input (known as its 'Key', and as its 'index number', as a String/Integer Value Input): 0
Output (known as its 'Value', as a String Value Output): "WHATEVER_OUTPUT_1"

Item 2:
Input (known as its 'Key', and as its 'index number', as a String/Integer Input Value Input): 1
Output (known as its 'Value', as a String Value Output): "WHATEVER_OUTPUT_2"

Item 3:
Input (known as its 'Key', and as its 'index number', as a String/Integer Value Input): 2
Output (known as its 'Value', as a String Value Output): "WHATEVER_OUTPUT_3"

Item 4:
Input (known as its 'Key', and as its 'index number', as a String/Integer Value Input): 3
Output (known as its 'Value', as a String Value Output): "WHATEVER_OUTPUT_4"

etc more or less items

Object List Attributes:

Item 1:
Input (known as its 'Key', and as its 'index number', as a String/Integer Value Input): 0
Output (known as its 'Value', as an Object reference/pointer Value Output, aka: the name of the Object): WHATEVER_NAME_OF_OBJECT_1

Item 2:
Input (known as its 'Key', and as its 'index number', as a String/Integer Value Input): 1
Output (known as its 'Value', as an Object reference/pointer Value Output, aka: the name of the Object): WHATEVER_NAME_OF_OBJECT_2

etc more or less items

Dictionary Attributes:

String Dictionary Attributes:

Item 1:
Input (known as its 'Key', as a String/Integer Value Input): "WHATEVER_INPUT_1"
Output (known as its 'Value', as a String Value Output): "WHATEVER_OUTPUT_1"

Item 2:
Input (known as its 'Key', as a String/Integer Value Input): "WHATEVER_INPUT_2"
Output (known as its 'Value', as a String Value Output): "WHATEVER_OUTPUT_2"

etc more or less items

Object Dictionary Attributes:

Item 1:
Input (known as its 'Key', as a String/Integer Value Input): "WHATEVER_INPUT_1"
Output (known as its 'Value', as an Object reference/pointer Value Output, aka: the name of the Object): WHATEVER_NAME_OF_OBJECT_1

Item 2:
Input (known as its 'Key', as a String/Integer Value Input): "WHATEVER_INPUT_2"
Output (known as its 'Value', as an Object reference/pointer Value Output, aka: the name of the Object): WHATEVER_NAME_OF_OBJECT_2

etc more or less items

Script Attributes:

Item 1:
Input (known as its 'Key', as a String/Integer Value Input): "WHATEVER_INPUT_1"
Output (known as its 'Value', as a Script Value Output, aka: add new script/s): (add new script/s)

Item 2:
Input (known as its 'Key', as a String/Integer Value Input): "WHATEVER_INPUT_2"
Output (known as its 'Value', as a Script Value Output, aka: add new script/s): (add new script/s)

etc more or less items

-----------

using List/Dictionary Attributes:

VARIABLE <===  ListItem (LIST, INPUT: index number)
// VARIABLE <=== (returned output from the 'StringListItem' Function)

VARIABLE <===  DictionaryItem (DICT, INPUT)
// VARIABLE <=== (returned output from the 'DictionaryItem' Function)

(there's also the specific return value type Functions too: StringListItem, ObjectListItem, StringDictionaryItem, ObjectDictionaryItem, and ScriptDictionaryItem)

example using a String List 'Variable' VARIABLE (instead of an 'Attribute' VARIABLE, as it's quicker to do/write it, lol), in code:

string_list_variable = Split ("red;blue;yellow", ";")
list_count_integer_variable = ListCount (string_list_variable)
last_index_number_integer_variable = list_count_integer_variable - 1
first_index_number_integer_variable = 0
random_list_viable_index_number_integer_variable = GetRandomInt (first_index_number_integer_variable, last_index_number_integer_variable)
string_variable = StringListItem (string_list_variable, random_list_viable_index_number_integer_variable)
msg (string_variable
// it'll display either (only one of them):
// red
// (or)
// blue
// (or)
// yellow

string_list_variable = Split ("red;blue;yellow", ";")
string_variable = StringListItem (string_list_variable, 0)
msg (string_variable)
// displays:
// red

string_list_variable = Split ("red;blue;yellow", ";")
string_variable = StringListItem (string_list_variable, 1)
msg (string_variable)
// displays:
// blue

string_list_variable = Split ("red;blue;yellow", ";")
string_variable = StringListItem (string_list_variable, 2)
msg (string_variable)
// displays:
// yellow

string_list_variable = Split ("red;blue;yellow", ";")
string_variable = StringListItem (string_list_variable, 3)
msg (string_variable)
// ERROR! (there is no 4th item!)

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

the 'Split' Function ONLY works for String Lists and String Dictionaries (well, I don't know if it works for Script Dictionary or not, but it does NOT work for Object Lists and Object Dictionaries):

otherwise, you HAVE TO (or can always just) use the 'NewList ()', NewDictionary (), NewStringList (), or NewObjectList' Functions, (and you may also be able to use the 'Set' Script/Function too, but am not sure), for example (using a String List):

// creating/setting a new/blank/(no-item) List/Dictionary, an (again, the) example (below uses a String List):

string_list_variable = NewStringList ()

// and then adding in the items to it:

list add (string_list_variable, "red")
list add (string_list_variable, "blue")
list add (string_list_variable, "yellow")