Attaching and changing attributes of player

Greetings ! I start to make new game recently and ran into one problem.
I'm not entiarly shure how exacly work attributes and how change them.
What I whant to do is change player "form\status" by using an item, but every time I use a debug menu, it's doesn't work properly as I want.
I will gladly accept any help, thanks.


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


here's some links to get you started (in particular, for Attribute usage and the 'if' Script usage, see my 'HK attributes and if script usage guide' link):

http://textadventures.co.uk/forum/general/topic/ljjm32av4e2t9ot49k478g/help#710be61e-eae1-4af1-8363-520cc718ba1c


Attributes:

in the GUI/Editor:

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

set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION

for examples:

(quest can parse/examine the Value, to know what type of Attribute you want it to be if the Attribute doesn't exist yet, as the Value Type must match up with the Attribute Type)

set variable player.strength = [EXPRESSION] 100 // Integer Attribute storing an Integer Value

set variable player.condition = [EXPRESSION] "normal" // String Attribute storing a String Value

set variable orc.dead = [EXPRESSION] false // Boolean Attribute storing a Boolean Value

// create ("katana") // for Object (pointer/reference) Attributes, the Value used, must be an actual existing Object, hence showing this line which would create a 'katana' Object, if the '//' comment symbols were removed to the left of 'create'

set variable player.weapon = [EXPRESSION] katana // Object (pointer/reference) Attribute storing an Object (pointer/reference) Value


human brains do this automatically, but computers need to be helped with data types, as they do matter, we just handle them automatically with our brains, lol:

Data Types:

Strings:

(aka: text): a collection of characters (alphabet and numeric) and/or symbols (some, not all)

anything within double quotes, is a String Value:

"1" --- this is a String Value, and NOT an amount Value
1 --- is an amount Value (an Integer)

Integers:

any non-decimal/fractional number

Doubles (Floats, Floating Points, decimal/fractional numbers):

any decimal/fractional number

Booleans:

either it's a 'true' or 'false' Value


here's an example for you:

<game name="NAME_OF_GAME">
</game>

<object name="room">

  <inherit name="editor_room" />

</object>

<object name="player">

  <inherit name="editor_object" />
  <inherit name="editor_player" />

  <attr name="parent" type="object">room</attr>

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

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

    if (player.condition = "poisoned") {

      poison_turnscript.enabled = true

    } else {

      if (poison_turnscript.enabled) {

        poison_turnscript.enabled = false

      }

      if (player.condition = "dead") {

        msg ("You died or were killed")

        msg ("GAME OVER")

        finish

      }

    }

  </attr>

  <attr name="life" type="string">999/999</attr>

  <attr name="maximum_life" type="int">999</attr>

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

    <![CDATA[

      if (player.current_life > player.maximum_life) {

        player.current_life = player.maximum_life

      } 

      player.life = player.current_life + "/" + player.maximum_life

    ]]>

  </attr>

  <attr name="current_life" type="int">999</attr>

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

    <![CDATA[

      if (player.current_life > player.maximum_life) {

        player.current_life = player.maximum_life

      } else if (player.current_life < 0) {

        player.current_life = 0

      }

      player.life = player.current_life + "/" + player.maximum_life

      if (player.current_life = 0) {

        player.condition = "dead"

      }

    ]]>

  </attr>

  <statusattributes type="stringdictionary">

    <item>

      <key>life</key>

      <value>Life: !</value>

    </item>

    <item>

      <key>condition</key>

      <value>Condition: !</value>

    </item>

  </statusattributes>

</object>

<object name="poisoned_apple">

  <attr name="parent" type="object">room</attr>

  <attr name="alias" type="string">poisoned apple</attr>

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

    if (player.condition = "normal")

      player.condition = "poisoned"

      msg ("You eat the poisoned apple, poisoning yourself")

      poisoned_apple.parent = internal_storage

    } else if (player.condition = "poisoned")

      msg ("You're already poisoned, silly")

    }

    // handling another condition that prevent being poisoned, or that you don't want to be over-ridden/over-rided by it: you don't want your current condition to change to being the 'poisoned' condition:

    // optional: 
    // else if (CONDITION_EXPRESSION) {
    // }
    // optional: more/additional else ifs
    // optional:
    // else {
    // }

  </attr>

</object>

<object name="cure_poison_potion">

  <attr name="parent" type="object">room</attr>

  <attr name="alias" type="string">cure poison potion</attr>

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

    if (player.condition = "poisoned") {

      player.condition = "normal"

      msg ("You use the pure poison item, curing you of poison")

      cure_poison_potion.parent = internal_storage

    } else {

      msg ("You realize you're NOT poisoned, just in time, preventing you from wasting this item when it wasn't needed to be used")

    }

  </attr>

</object>

<object name="internal_storage">
</object>

<verb>

  <property>eat</property>

  <pattern>eat</pattern>

  <defaultexpression>You can't eat that!</defaultexpression>

</verb>

<verb>

  <property>drink</property>

  <pattern>drink</pattern>

  <defaultexpression>You can't drink that!</defaultexpression>

</verb>

<turnscript name="poison_turnscript">

  <attr name="enabled" type="boolean">false</attr>

  <script>

      player.current_life = player.current_life - 100

      msg ("The poisoning takes its toll on you! (-100 current life)")

  </script>

</turnscript>

P.S.

if you want to be able to have multiple conditions at the same time, then we'd need to use List/Dictionary Attributes for our 'condition' Attribute, and add/remove the condition items from our 'condition' List/Dictionary Attribute/s

(or you can also instead do Boolean Attributes for each condition... which is easier than learning to use Lists/Dictionaries, but not as effective... if you got a lot of conditions and etc functionality with/involving them)

(in my example, our single 'condition' Attribute is a String Attribute, which can only hold 1 Value, so only one condition at a time for this specific 'condition' String Attribute)


It depends on if you are using online or offline version and what type of attribute it is. First it must be added to the players attributes then when wanting to change it you just call player.attribute = (x) or if doing maths
player.attribute = player.attribute + 6 using maths you can use any math sign doesn't have to just add.


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

Support

Forums