Money system

I seem to be having issues with the new money system. I successfully made it so the player got 10 dollars. I have an item with a price. No matter what the price is it doesnt change the amount of dollars i have. which doesnt make much sense. If the price is 11 i can still pick the item up. Is this feature not working yet or am i missing something weird.


Hello.

I believe you have to set everything up like you want it.


A Very Simple System

Make a function for taking items which can be purchased, then run that function for the take script.

Here's a basic version:

  <function name="takeSaleItem" parameters="this">
    if (HasAttribute(this, "purchased")) {
      msg ("You pick " + this.article + " up.")
      AddToInventory (this)
    }
    else {
      msg ("You'll need to buy " + this.article + ".  Taking " + this.article + " before buying " + this.article + " would be theft.")
    }
  </function>

Set up a buy;purchase verb on each object, which calls a function created to handle purchasing.

Here's a simplified example:

  <function name="makePurchase" parameters="this"><![CDATA[
    if (game.pov.money >= this.price) {
      DecreaseMoney (this.price)
      msg ("You pay for " + GetDisplayName(this) + " and pick " + this.article + " up.")
      AddToInventory (this)
      this.buy = "You have already purchased " + this.article + "."
      this.purchased = true
      if (ListContains(this.generatedverbslist, "buy")) {
        list remove (this.generatedverbslist, "buy")
      }
    }
    else {
      msg ("You don't have enough money.")
    }
  ]]></function>

I would normally have a shopkeeper to talk to (and haggle with).

I would also normally clone the purchased item and move it to the player's inventory, changing all sorts of attributes on the cloned object in that script. (This would depend on what objects are for sale, of course)


Here's a quick example game using the scripts I posted above:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Shopping">
    <gameid>007a2efc-0e12-4508-9148-bafaca356f42</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <showmoney />
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <money type="int">10</money>
    </object>
    <object name="Doohickey">
      <inherit name="editor_object" />
      <price type="int">5</price>
      <buy type="script">
        makePurchase (this)
      </buy>
      <take type="script">
        takeSaleItem (this)
      </take>
    </object>
    <object name="Collection of Fancy Thingies">
      <inherit name="editor_object" />
      <inherit name="plural" />
      <take type="script">
        takeSaleItem (this)
      </take>
      <price type="int">11</price>
      <buy type="script">
        makePurchase (this)
      </buy>
    </object>
  </object>
  <function name="makePurchase" parameters="this"><![CDATA[
    if (game.pov.money >= this.price) {
      DecreaseMoney (this.price)
      msg ("You pay for " + GetDisplayName(this) + " and pick " + this.article + " up.")
      AddToInventory (this)
      this.buy = "You have already purchased " + this.article + "."
      this.purchased = true
      if (ListContains(this.generatedverbslist, "buy")) {
        list remove (this.generatedverbslist, "buy")
      }
    }
    else {
      msg ("You don't have enough money.")
    }
  ]]></function>
  <function name="takeSaleItem" parameters="this">
    if (HasAttribute(this, "purchased")) {
      msg ("You pick " + this.article + " up.")
      AddToInventory (this)
    }
    else {
      msg ("You'll need to buy " + this.article + ".  Taking " + this.article + " before buying " + this.article + " would be theft.")
    }
  </function>
</asl>

You can set up shops and all sorts of things, if you want, too.

Further reading:

https://github.com/ThePix/quest/wiki/Setting-Up-Shop


Thank you. I dont know how to program and even just looking at it in the folder view is a bit overwhelming. I dont fully understand the expressions and stuff so every complicated thing i do it usually a crazy list of IF and object flags haha.


I can provide an example with screenshots, if that will help you out...


Oh i put the code you provided into the game and switched over to the folder view. Im just saying even that is a bit overwellming. Im trying to pick through it and figure out how to use it best.


it's not too hard to learn how to read and write code, but it's scary at first...

the physical things are made up of 'tag' lines/blocks (like in writing you got: 'sentence' lines and 'paragraph' blocks):

a coding tag line/block, has a beginning and an ending, just as sentences and paragraphs do:

(coding, in general: depends upon programing language/software used, can be vertical or horizontal)

a vertical tag block:

<object name="ball"> // starting 'tag' of our 'ball' Object tag block
  // content (other Objects and/or Attributes)
</object> // ending 'tag' of our 'ball' Object tag block

// without my (cluttering) comment lines (except one new comment line, as I also added in some example content into it too):

<object name="ball">

  <attr name="color" type="string">red</attr>
  <attr name="shape" type="string">sphere</attr>
  <attr name="material" type="string">rubber</attr>
  <attr name="type" type="string">superball</attr>

  <attr name="displayverbs" type="listextend">throw</attr>

  <attr name="throw" type="script">
    msg ("You throw the " + ball.color + " " + ball.shape + " " + ball.material + " " + ball.type + " at the wall")
    // output/display/result: You throw the red sphere rubber superball at the wall
  </attr>

</object>

<verb>

  <property>throw</property>
  <pattern>throw</pattern>

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

</verb>

horizontal tag line example (Attributes DO HAVE TO BE contained within Elements, but that isn't shown below):

<attr name="color" type="string">red</attr>

here's a pseudo-code example of a default (english language quest.exe download) new game's full game code:

with human-friendly spacing:

<asl version="550">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <game name="NAME_OF_YOUR_GAME">

    <gameid>SOME_RANDOMLY_GENERATED_HAS_STRING</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>

  </game>

  <object name="room">

    <inherit name="editor_room" />

    <object name="player">

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

    </object>

  </object>

</asl>

without human-friendly spacing:

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="NAME_OF_YOUR_GAME">
    <gameid>SOME_RANDOMLY_GENERATED_HAS_STRING</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
</asl>

fully horizontal (VERY NOT human-friendly) code:

<asl version="550"><include ref="English.aslx" /><include ref="Core.aslx" /><game name="NAME_OF_YOUR_GAME"><gameid>SOME_RANDOMLY_GENERATED_HAS_STRING</gameid><version>1.0</version><firstpublished>2017</firstpublished></game><object name="room"><inherit name="editor_room" /><object name="player"><inherit name="editor_object" /><inherit name="editor_player" /></object></object></asl>

as you can see... humans like vertical (and line-spaced) code (horizontal code is fine though for short code, aka tag lines like with/of some Attributes, content), lol


anyways about the code...


<asl version="550">
  // mass of your entire game code's code/content
</asl>

the 'asl' tag block IS your GAME (your GAME OBJECT), so everything must be within it, obviously

obviously the 'asl' tag block (aka, your GAME / GAME OBJECT) is required, lol

the 'version' in the starting 'als' tag (the starting tag is known as the 'signature/header' too, as it often has special parameters like 'name=xxx', 'type=xxx', etc, or in this case, 'version=xxx'), needs to match up with your downloaded quest version. There's a bit of more details/explanation about checking/matching up it as the correct quest version, but I'm too lazy to explain it here/now, lol


<game name="NAME_OF_YOUR_GAME">
</game>

the 'game' Game Settings Object is a special Object that is required, containing content for info about your game for people to read to see if they want to play your game or not, and etc such stuff (author, gameid, version: this is merely your own versioning/patching/updating history, first published year, category, difficulty, cruelty, description of your game, etc ect etc) and some various game-wide (global) controls and settings, and also the useful 'start' Script Attribute.


<include ref="English.aslx" />
<include ref="English.aslx" />

quest is very powerful, it's engine is actually made up of library (literally code) files, so if you know quest well and are a good programmer, you can create your very own unique quest engine!

anyways, these are the default (for english language quest.exe downloads) quest engine library files, obviously required (unless you've downloaded a different language than english and/or created your own engine library files, lol)

you don't have to create engine library files, as they can be as simple library files as you want, for an example of the most simple library file:

my_dragon_library_file.aslx

<library>

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

</library>

literally this library file is just adding a 'dragon' Object within your 'room' Room Object, lol:

(the 'my_dragon_library_file.aslx' library file has to be within the same folder as your 'xxx.aslx' game file, so it can be found and used)

<asl version="550">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <include ref="my_dragon_library_file" />

  <game name="NAME_OF_YOUR_GAME">

    <gameid>SOME_RANDOMLY_GENERATED_HAS_STRING</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>

  </game>

  <object name="room">

    <inherit name="editor_room" />

    <object name="player">

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

    </object>

  </object>

</asl>

which is absolutely no different than had you just done this:

<asl version="550">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <game name="NAME_OF_YOUR_GAME">

    <gameid>SOME_RANDOMLY_GENERATED_HAS_STRING</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>

  </game>

  <object name="room">

    <inherit name="editor_room" />

    <object name="player">

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

    </object>

  </object>

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

</asl>

making library files are useful, as you can think of them as folders, so you can organize your code, making it easier on you, instead of having all of your code in one "folder" (aka, your game file).


I think you get the idea now... hopefully... You hopefully understand the 'room' and 'player' Objects / tag blocks, that I don't have to explain them.


aside from the "physical things" (the 'tag' stuff), there's also 'scripting' (actions/events) code (all the NON-tag stuff) too... which is it's own beast, so we won't get into it here, lol... well....

quick example only:

<game name="example_game">
  <attr name="start" type="script">
    character_creation
    on ready {
      msg (player.alias + " is a " + player.age_integer + " year old " + player.age_string + " " + player.sex + " " + player.race + " " + player.class + ".")
    }
  </attr>
</game>

<function name="character_creation">
  <![CDATA[
    msg ("Name?")
    get input {
      player.alias = result
      msg ("Age?")
      get input {
        player.age_integer = ToInt (result)
        if (player.age_integer > 17) {
          player.age_string = "adult"
        } else if (player.age_integer > 12) {
          player.age_string = "teen"
        } else if (player.age_integer > 2) {
          player.age_string = "child"
        } else {
          player.age_string = "baby"
        }
        show menu ("Sex?", split ("male;female", ";"), false) {
          player.sex = result
          show menu ("Race?", split ("human;elf;dwarf;gnome;halfling;giant", ";"), false) {
            player.race = result
            show menu ("Class?", split ("warrior;thief;cleric;wizard", ";"), false) {
              player.class = result
            }
          }
        }
      }
    }
  ]]>
</function>

the "physical things" in quest are known as 'Elements (OBJECTS)' (not to be confused with the 'Object' sub-Element/sub-OBJECT), and they (well, some/most of them) are:

http://docs.textadventures.co.uk/quest/elements/

<asl version="###">
</asl>

<include ref="xxx.aslx" />

<delegate name="xxx" />

<game name="xxx">
</game>

<object name="xxx">
</object>

<exit name="xxx">
</exit>

<type name="xxx">
</type>

<turnscript name="xxx">
</turnscript>

<timer name="xxx">
</timer>

<function name="xxx">
</function>

<command name="xxx">
</command>

<verb>
</verb>

Attributes:

http://docs.textadventures.co.uk/quest/types/


Functions:

http://docs.textadventures.co.uk/quest/scripts/

http://docs.textadventures.co.uk/quest/functions/ // (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html) // (alphabetical order)


quest doc site main page:

http://docs.textadventures.co.uk/quest/


tutorial:

http://docs.textadventures.co.uk/quest/tutorial/


one such guide (there's more via links on the quest doc main page or where-ever on/navigated-on the quest doc site, lol):

http://docs.textadventures.co.uk/quest/#Howto

more guides:

http://textadventures.co.uk/forum/samples


my own 'Attribute and 'if' Script usage (and more detailed code help/explanation) guide:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk


ask if you need any help/explantions about anything!


Log in to post a reply.

Support

Forums