item purchase/price?

Hi everyone, im currently building a game on quest online and have implemented the money system. I would like to know what the simplest way of requiring the player to have and exchange a certain amount of money to purchase an item is. Thank you in advance!


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


an example (using scripting) of (the illusion of) transactions:

Attribute Manipulation

player.currency = 300

create ("shop_owner")
shop_owner.parent = room
shop_owner.currency = 500

create ("katana")
katana.price = 100
katana.parent = shop_owner

shop_owner.buy => {
  if (katana.parent = shop_owner) {
    if (player.currency >= katana.price) {
      player.currency = player.currency - katana.price
      shop_owner.currency = shop_owner.currency + katana.price
      katana.parent = player
      msg ("You buy the katana from the shop owner")
    } else {
      msg ("You don't have enough currency to buy the katana from the shop owner")
    }
  } else {
    msg ("The shop owner has no katanas to sell to you")
  }
}

shop_owner.sell => {
  if (katana.parent = player) {
    if (shop_owner.currency >= katana.price / 2) {
      shop_owner.currency = shop_owner.currency - katana.price / 2
      player.currency = player.currency + katana.price / 2
      katana.parent = shop_owner
      msg ("You sell the katana to the shop owner")
    } else {
      msg ("The shop owner doesn't have enough currency to buy the katana from you")
    }
  } else {
    msg ("You don't have a katana to sell to the shop owner")
  }
}

do (shop_owner, "buy")

do (shop_owner, "sell")

when selling, it's common in RPGs (as having a mercantile/haggling system is more complex like found in, at least, TES: Morrowind --- I've not played TES:Oblivion nor TES:Skyrim), that you only sell an item for half of its price, so that's why I got the '/ 2' (dividing by half:2)


the 'shop_owner.buy' and 'shop_owner.sell' Script Attributes ("Verbs"), need the 'CDATA' tags, for the '<,>' symbols to be parsed/understood as being the 'greater than, lesser than' operations/symbols, but I'm not sure on the correct syntax for it when used with the scripting for creating Script Attributes ("Verbs"):

maybe like this? ......

shop_owner.buy =>

  <![CDATA[

    {

      if (katana.parent = shop_owner) {
        if (player.currency >= katana.price) {
          player.currency = player.currency - katana.price
          shop_owner.currency = shop_owner.currency + katana.price
          katana.parent = player
          msg ("You buy the katana from the shop owner")
        } else {
          msg ("You don't have enough currency to buy the katana from the shop owner")
        }
      } else {
        msg ("The shop owner has no katanas to sell to you")
      }

    }

  ]]>

shop_owner.sell =>

  <![CDATA[

    {

      if (katana.parent = player) {
        if (shop_owner.currency >= katana.price / 2) {
          shop_owner.currency = shop_owner.currency - katana.price / 2
          player.currency = player.currency + katana.price / 2
          katana.parent = shop_owner
          msg ("You sell the katana to the shop owner")
        } else {
          msg ("The shop owner doesn't have enough currency to buy the katana from you")
        }
      } else {
        msg ("You don't have a katana to sell to the shop owner")
      }

    }

  ]]>

learning to use (basic) Attributes ('Attribute' VARIABLES) and the 'if' Script is not easy if you're new to coding, but in doing so, you can do 90% of everything that you want to do for/within your game/game-making. Learning more coding, for better or worse, gets into diminishing returns (for example, learning to use List/Dictionary Attributes adds 5%, for 95% = 90% + 5%, of doing everything that you want to do for/within your game/game-making).

here's some help on using quest and with learning to code with quest:

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

and specifically, here's a detailed guide on learning to use (basic) Attributes and the 'if' Script:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk (the first/upper part/half is on a bit of the coding structure of quest, near the middle is the start of the guide on using Attributes and the 'if' Script, and near the bottom of this link's first post is the part on doing transactions: buying/selling)

(though, it's probably not easy to understand if you're new to coding, as I'm not good at explaining, better to find Pixie's and/or KV's posts/threads, as they're easier to understand than mine)


There is a tutorial that might be useful:
http://docs.textadventures.co.uk/quest/shop.html


the 'shop_owner.buy' and 'shop_owner.sell' Script Attributes ("Verbs"), need the 'CDATA' tags, for the '<,>' symbols to be parsed/understood as being the 'greater than, lesser than' operations/symbols

No, they don't.
When loading an XML document, you need a CDATA block to tell the XML parser that the < and > characters should be passed on to the IScript parser, rather than interpreted as XML.

The script block following the => operator doesn't need a CDATA block around it, because it's being handed directly to the IScript constructor; the XML parser isn't being run at that point. In this case, the CDATA tags should be around the entire script that contains the shop_owner.buy => { line.


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


ah, thanks for explaining it! (I'm still pretty new/ignorant of wrappers, compiling, translating, etc, parsers, and etc internal coding constructs and its operations, in how quest works internally, so this explanation has been of great help in understanding it better)

so, you mean like this, then (if I understand):

<game name="EXAMPLE">

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

    <![CDATA[

      player.currency = 300

      create ("shop_owner")
      shop_owner.parent = room
      shop_owner.currency = 500

      create ("katana")
      katana.parent = shop_owner
      katana.price = 100

      shop_owner.buy =>  {
        if (katana.parent = shop_owner) {
          if (player.currency >= katana.price) {
            player.currency = player.currency - katana.price
            shop_owner.currency = shop_owner.currency + katana.price
            katana.parent = player
            msg ("You buy the katana from the shop owner")
          } else {
            msg ("You don't have enough currency to buy the katana from the shop owner")
          }
        } else {
          msg ("The shop owner has no katanas to sell to you")
        }
      }

      shop_owner.sell => {
        if (katana.parent = player) {
          if (shop_owner.currency >= katana.price / 2) {
            shop_owner.currency = shop_owner.currency - katana.price / 2
            player.currency = player.currency + katana.price / 2
            katana.parent = shop_owner
            msg ("You sell the katana to the shop owner")
          } else {
            msg ("The shop owner doesn't have enough currency to buy the katana from you")
          }
        } else {
          msg ("You don't have a katana to sell to the shop owner")
        }
      }

      do (shop_owner, "buy")

      do (shop_owner, "sell")

    ]]>

  </attr>

</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>

</object>

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

Support

Forums