Shop!

Ok, so in my game I'm making a shop. I'm new to this, so I decided to use a tutorial to help me out a bit. I used this one: http://docs.textadventures.co.uk/quest/shop.html
The only problem is- at the end, it's very vague on how to set up the actual shop, and every time I paste the code in, it says there was an internal error, refreshes, and I have to start over.
(Keep in mind I do use the online version, so that might be what is causing it, I don't know)
This is extremely frustrating and time consuming!
Please help!


So... You just want to make a shop? Just click "add room" and name it "Shop".


Which part of the code is giving you the error? Is it the final SetUpShop (shop, stock)?
On that line, you should replace shop with the name of the room that is your shop, where the player goes to buy stuff. And replace stock with the name of a room (probably one the player can't get to) containing all the items that the shop will sell.


K.V.

(Keep in mind I do use the online version, so that might be what is causing it, I don't know)

The online editor does that when pasting complicated code.

I get it to work by entering one line (or section), then exiting code view, then going back into code view and entering another bit...

Rinse and repeat.


Sometimes, it flat out won't take the code, but you can enter the same thing via GUI, too.

Just do one line at a time (or one section, if you have a change script), and you will find your problem code.


I just quickly glanced at Pixie's library/guide (the link you provided), so I might have this totally wrong...

if you've done all of the other code stuff that Pixie had you do, correctly, then you just to do set up your shops like this, an example:

(showing pseudo in-code, as it's easier to understand, but you got to figure-out or know to do this stuff yourself with the online quest, but-and if not, then just ask us for help!, hehe)

// this code is JUST an example of what it looks like for doing the last part of pixie's library/guide, as I'm sure I'm missing a lot of other stuff that is needed to be done for the rest of Pixie's guidance-instructions-stuff (that I hadn't looked/studied yet, as I just did a quick glance over it)

// -----------------------------------------------------------------------------

<game name="example_game">
  <attr name="start" type="script">
    SetUpShop (melee_shop, melee_stock)
    SetUpShop (projectile_shop, projectile_stock)
  </attr>
</game>

<object name="melee_shop">
  // blah Attributes and/or other Objects and/or Exits
</object>

<object name="projectile_shop">
  // blah Attributes and/or other Objects and/or Exits
</object>

<object name="melee_stock">
  // blah Attributes and/or other Objects
  <object name="mace">
    // blah Attributes and/or other Objects
  </object>
  <object name="sword">
    // blah Attributes and/or other Objects
  </object>
  <object name="axe">
    // blah Attributes and/or other Objects
  </object>
</object>

<object name="projectile_stock">
  // blah Attributes and/or other Objects
  <object name="bow">
    // blah Attributes and/or other Objects
  </object>
  <object name="crossbow">
    // blah Attributes and/or other Objects
  </object>
  <object name="gun">
    // blah Attributes and/or other Objects
  </object>
</object>

(moderators: this post can be deleted)


test

HK edit:

I give up, I have absolutely no idea why its blocking me from pasting my code in as an edited post nor into a new post... (it just won't post/submit/update the post... no idea why).... argh...


K.V.

Does it have RegEx in it?

The forum doesn't like certain RegEx patterns...

The online editor probably doesn't like the same ones, upon reflection.


wow, it even gave an error in trying to pm it to you... makes me want to figure-out/crack what is causing it to block my post, lol.

none of my tricks to get it to post are working... either... very perplexing... lol


HK Edit: unfortunately, this is only useful if you're using the offline/desktop version


Alternatively, I think you could do this structural/organizational design too (and hopefully it still works with Pixie's design):

<game name="example_game">
  <attr name="start" type="script">
    SetUpShop (melee_shop, melee_stock)
    SetUpShop (projectile_shop, projectile_stock)
  </attr>
</game>

<object name="shop_data_object">

  <object name="sword_shop">
    // blah Attributes and/or other Objects and/or Exits
  </object>
  <object name="bow_shop">
    // blah Attributes and/or other Objects and/or Exits
  </object>
  <object name="axe_shop">
    // blah Attributes and/or other Objects and/or Exits
  </object>
  <object name="crossbow_shop">
    // blah Attributes and/or other Objects and/or Exits
  </object>
  <object name="mace_shop">
    // blah Attributes and/or other Objects and/or Exits
  </object>
  <object name="gun_shop">
    // blah Attributes and/or other Objects and/or Exits
  </object>

</object>

<object name="stock_data_object">

  <object name="sword_stock">
    // blah Attributes and/or other Objects
  </object>
  <object name="bow_stock">
    // blah Attributes and/or other Objects
  </object>
  <object name="axe_stock">
    // blah Attributes and/or other Objects
  </object>
  <object name="crossbow_stock">
    // blah Attributes and/or other Objects
  </object>
  <object name="mace_stock">
    // blah Attributes and/or other Objects
  </object>
  <object name="gun_stock">
    // blah Attributes and/or other Objects
  </object>

</object>

<object name="equipment_data_object">

  <object name="weapon_data_object">

    <object name="melee_data_object">

      <object name="mace_data_object">

        <object name="mace">
          <attr name="parent" type="object">mace_stock</attr>
          // blah Attributes and/or other Objects
        </object>
        <object name="flail">
          <attr name="parent" type="object">mace_stock</attr>
          // blah Attributes and/or other Objects
        </object>
        <object name="battlehammer">
          <attr name="parent" type="object">mace_stock</attr>
          // blah Attributes and/or other Objects
        </object>

      </object>

      <object name="sword_data_object">

        <object name="katana">
          <attr name="parent" type="object">sword_stock</attr>
          // blah Attributes and/or other Objects
        </object>
        <object name="claymore">
          <attr name="parent" type="object">sword_stock</attr>
          // blah Attributes and/or other Objects
        </object>
        <object name="flamberge">
          <attr name="parent" type="object">sword_stock</attr>
          // blah Attributes and/or other Objects
        </object>

      </object>

ah... I'm so awesome, I'm so awesome! I got .... half of it posted... lol

(it just came to me to try the same method of figuring out what part of one's code doesn't work: remove parts of it until you find the cultprit part)


let's see if I can post the remaining half of it...

  <object name="axe_data_object">

    <object name="axe">
      <attr name="parent" type="object">axe_stock</attr>
      // blah Attributes and/or other Objects
    </object>
    <object name="tomahawk">
      <attr name="parent" type="object">axe_stock</attr>
      // blah Attributes and/or other Objects
    </object>
    <object name="hatchet">
      <attr name="parent" type="object">axe_stock</attr>
      // blah Attributes and/or other Objects
    </object>

  </object>

</object>

<object name="projectile_data_object">

  <object name="bow_data_object">

    <object name="long_bow">
      <attr name="parent" type="object">bow_stock</attr>
      // blah Attributes and/or other Objects
    </object>
    <object name="short_bow">
      <attr name="parent" type="object">bow_stock</attr>
      // blah Attributes and/or other Objects
    </object>
    <object name="recurve_bow">
      <attr name="parent" type="object">bow_stock</attr>
      // blah Attributes and/or other Objects
    </object>

  </object>

  <object name="crossbow_data_object">

    <object name="crossbow">
      <attr name="parent" type="object">crossbow_stock</attr>
      // blah Attributes and/or other Objects
    </object>
    <object name="repeating_crossbow">
      <attr name="parent" type="object">crossbow_stock</attr>
      // blah Attributes and/or other Objects
    </object>
    <object name="ballista">
      <attr name="parent" type="object">crossbow_stock</attr>
      // blah Attributes and/or other Objects
    </object>

  </object>

  <object name="gun_data_object">

    <object name="hand_gun">
      <attr name="parent" type="object">gun_stock</attr>
      // blah Attributes and/or other Objects
    </object>
    <object name="machine_gun">
      <attr name="parent" type="object">gun_stock</attr>
      // blah Attributes and/or other Objects
    </object>
    <object name="rifle">
      <attr name="parent" type="object">gun_stock</attr>
      // blah Attributes and/or other Objects
    </object>

  </object>

</object>
```

yep.... hmm... must be character count... it seems... (that would explain why none of my tricks worked, as none of them involved making the post signficantly shorter, lol) ... be nice if got a better error message, like: 'Error: post is too long', lol...


except... I've surely posted longer posts then this... as I post long posts often (am very verbose)....

hmm... HK is still really baffled.... it seems to be character count... but it can't be...... hmm... yes, very baffled.... lol


K.V.

HK

Make it into a Gist on GitHub, then put the link here.


What's a GitHub?


K.V.

Oh, sorry fuzzybunny2203.

I was suggesting to HK that he try to post his code that way.

...but:


From http://docs.textadventures.co.uk/forum/

For a code sample that’s too large for a post, you can create a Github gist, then post a link to the gist on the forum.


I have checked the tutorial, and I was able to create a shop using the online editor; there is nothing in the code that will cause Quest to choke (that said, it is just possible it is browser specific; I was using Firefox 55). I have added a couple of images that may help, and an example shop at the end.


Is shop an object or a room? I have it as a room (because I want the player to be able to go into it) but if the programming is set for an object and a room (the stockroom) that might be the problem.


technical info:

at the quest user level: 'Room Objects', 'Player Objects', and '(non-room and non-player) Objects', are all Objects. Quest's GUI/Editor makes it easier for you to assign their Attributes and to set them up for you, but any Object can be made into a 'Room Object', 'Player Object', and/or '(non-room and non-player) Objects'. Objects are Objects, only their Attributes differentiates them.

in the underneath/underlying quest source code: All Elements (Objects, Exits, Verbs, Commands, Functions, Turnscripts, Timers, Object Types / Types, etc) are OBJECTS/CLASSES.


You need a shop Object in your game, whether you use a shop building (Room Object) or a shop owner npc (Object), is up to you and your game design.

I believe with Pixie's quest library, you need to give that shop either (not sure which it is, but Pixie has instructions on how to use his library):

  1. a 'shop' Boolean Attribute
  2. a 'shop' String Attribute
  3. a 'shop' Object Type / Type / Inherited Attribute
// Boolean Attribute:

<object name="example_shop">
  <attr name="shop" type="boolean">true</attr>
</object>

// scripting examples:

if (HasBoolean (example_object, "shop")) { msg ("TRUE") } else { msg ("FALSE") }
if (example_object.shop) { msg ("=TRUE")  } else { msg ("=FALSE") }

// ---------------------------------------------------------

// String Attribute:

(actually, Pixie probably doesn't use a String Attribute, as it's a bit weird having a 'shop' String Attribute with a 'shop' Value. I would re-name/re-label the String Attribute as a 'type_of_object' String Attribute with whatever Value for the type of in-game Object I want it to be indicated/flagged as being: 'shop', 'inn/tavern', 'dungeon', 'cave', 'furniture', 'equipment', 'spell', 'item', 'npc', 'monster', etc etc etc. But, I'm not Pixie, lol.)

<object name="example_shop">
  <attr name="shop" type="string">shop</attr>
</object>

// scripting examples:

if (HasString (example_object, "shop")) { msg ("TRUE") } else { msg ("FALSE") }
if (GetString (example_object, "shop") = "shop") { msg ("=TRUE")  } else { msg ("=FALSE") }
if (example_object.shop = "shop") { msg ("=TRUE")  } else { msg ("=FALSE") }

// I'd re-name/re-label it as:

if (GetString (example_object, "type_of_object") = "shop") { msg ("TRUE") } else { msg ("FALSE") }
if (example_object.type_of_object = "shop") { msg ("=TRUE")  } else { msg ("=FALSE") }

// ---------------------------------------

// Object Type / Type / Inherited Attribute:

<object name="example_shop">
  <inherit name="shop" />
</object>

<type name="shop">
  // blah Attributes
</type>

// scripting example:

if (DoesInherit (example_object, "shop")) { msg ("TRUE") } else { msg ("FALSE") }

to indicate/flag to quest and Pixie's library that, that Object is to be (treated/handled as) a shop.


You have to make a object for the shop.

Do not paste the code in directly I messed up the bracket numbers/places.
These are the buying commands. These are a little complicated.
Before you start, make an object to be the shop first.
There is also an option involving "price," which I have not figured out yet. But if you change the "player.gold" to "player.price," it should work itself out, somehow.

Buy command
I'm pretty sure "buy" is already a command that comes with quest, so it will have to be capitalized or "buy1". But name it whatever you wish.
Type Buy #object# as the command pattern. (Or whatever you want.)
Do not paste in directly. I messed up the bracket numbers/places.

msg ("See something that catches your eye?")
options = Split("Potion (50);Hyper Potion (200)", ";")
ShowMenu ("Shop", options, true) {
  switch (result) {
    case ("Potion (50)") {
      if (player.gold >= 50) {
        player.gold = player.gold - 50
        player.potion = player.potion + 1
        msg ("You bought a Potion.")
      }
      else {
        msg ("You don't have enough gold.")
      }
    }
    case ("Hyper Potion (200)") {
      if (player.gold >= 200) {
        player.gold = player.gold - 200
        player.hyper_potion = player.hyper_potion + 1
        msg ("You bought a Hyper Potion.")
      }
      else {
        msg ("You don't have enough gold.")
      }
    }
  }
}

Sell command
I'm pretty sure "sell" is also a command in Quest, so you'll have to name it something else.
Type Sell #object# as the pattern.

msg ("What do you have?")
options = Split("Potion (50);Hyper Potion (200)", ";")
ShowMenu ("Shop", options, true) {
  switch (result) {
    case ("Potion (50)") {
      if (player.potion > 0) {
        player.gold = player.gold + 50
        player.potion = player.potion - 1
        msg ("You sold a potion.")
      }
      else {
        msg ("You don't have any Potions.")
      }
    }
    case ("Hyper Potion (200)") {
      if (player.hyper_potion > 0) {
        player.gold = player.gold + 200
        player.hyper_potion = player.hyper_potion - 1
        msg ("You sold a Hyper Potion.")
      }
      else {
        msg ("You don't have any Hyper Potions.")
      }
    }
  }
}

@fuzzybunny2203

Is shop an object or a room? I have it as a room (because I want the player to be able to go into it) but if the programming is set for an object and a room (the stockroom) that might be the problem.

With the code you linked in the first post, it should be a room.

Can you show us your game? Maybe I can take a look and try to figure out the problem.

@hegemonkhan

I believe with Pixie's quest library, you need to give that shop either (not sure which it is, but Pixie has instructions on how to use his library):

Actually you're wrong here; it needs a 'stock' attribute which is a reference to the stockroom. This is created by the SetUpShop(shop, stockroom) function.

(An interesting aside: The shop library uses an inaccessible room to store its stock. But if you make a stockroom that you can actually get to, you can get items for free by stealing them from the stockroom; and the shop will happily sell you back any items you drop there. I think that's kind of a funny way to do it)


agh... I'm getting old... I just remembered that I was posting in some other thread on Pixie's 'shop' library, where the OP needed help with it, having skimmed over Pixie's 'shop' library, with the 'SetUpShop (shop, stock)', and posted about in that other thread. And you posted/helped in that other thread too... my short term memory is really diminishing... sighs.

But, I totally forgot about that when I posted here in this thread about the 'shop' Boolean Attribute... sighs... getting old sucks. My short-term memory is going... bye bye... sighs. (In Pixie's original shop library, it was much more simple, using a 'shop' Boolean Attribute to flag/indicate for handling as a 'shop' Object)


ya, 'shop' coding/design can be simple, or advanced: dealing with stealing/stealth/theft and also ownership (as to who/what contains the items and thus connected to stealing/stealth/theft and also if you can sell back items or not) features... (see TES: morrowind's shopping design, and probably Oblivion and Skyrim too, but I've not played them)


With regard to stealing etc. … I'm always amused when I try something unexpected, and the library responds in a way that feels vaguely sane. I like to think that's one sign of a well-designed library: Its behaviour makes some kind of sense when you do something the creator might not have expected.


well, it depends on what you want for game design, and on how much handling of user input you put into it.

Pixie is assuming you'll follow his directions and have the 'stock' rooms be non-in-game visitable, so he doesn't have any handling upon the shop mechanics for them. He could have put in the handling on them too, if he wanted to assume users would not follow his instructions and make/have their stock rooms visitable in-game, and/or if that is what he intended for his design, or maybe he intentionally wants the design to be that way, should the user make/have the 'stock' rooms be visitable in-game.


its a judgement call in how much user handling you want to put into your code, you obviously want to prevent any bugs/errors/crashes/hack'ability/etc, but you don't want to waste your time handling ever single thing (can be infinite or near-infinite) the user can do, and you want to assume the user is not a complete idiot or jerk (and if he is, that's his fault then)... as your "developer time" is precious.


Ok, I've sorta figured out the problem- well, at least it's not saying 'internal error' anymore! Now it has a different error message: Error running script: Error compiling expression 'stock': Unknown object or variable 'stock'
I guess this means I have to make an object or variable 'stock'? How do I do this?
Please note I'm new, so I'd love to be taken by the hand and walked through the whole process! (Bonus side is you'll feel superior 😉)


You shouldn't have to create a variable 'stock'. The SetUpShop() function does this for you.

I'm happy to help, but an error message doesn't mean much if I can't see the code that generates it. If you're using the online editor, maybe you could publish the game (choose to only let people with the link play it) and then share the link, so I can see what the problem is.

My best guess (and it's just a guess) is that you've typed:
SetUpShop (shop, stock)

In that command you aren't supposed to literally type "shop" or "stock". Maybe it would be better phrased as:
SetUpShop( the name of the room that the player can go into to buy stuff, the name of a room or container that has all the items for sale inside it)

(sorry if that seems a bit condescending. It's a common mistake, so without seeing your code that's the first guess that comes to mind)


No, I have actually put in the name of the shop (it's an armoury) and the name of the stockroom.
Error message comes up at the beginning of the game.
Not sure if it would help to share as the shop comes in a lot later and you have to pass all this stuff to get to it...

I'm also not sure if you can 'skip' elements of the game (or teleport because that would really help when testing the game.)


I can't see anywhere else that error message is likely to have come from. The only advice I can give is to look over the code and make sure you haven't made any errors copying it out.

I'm quite willing to help out; a second pair of eyes is always good for catching things you might have missed.


@fuzzybunny2203 EVERY TIME, I get that error, I have a "spelling", or "grammar"/programming mistake, somewhere.


Jmnevil54, I feel your pain!


Nope, I've checked it, had a few minor errors at the beginning (which I fixed) but the error message still shows... Dunno what to do... It still has a problem with the stock, not with the actual shop.


Could you paste the actual error message into a post? Might be useful if you could also paste in the code as well from the start script of the game object.


Edit: Just had a quick look at it.

In the function SetUpShop, you've named the parameters Shop and Stock, with capital letters. Try changing them to shop and stock.


Oh my gosh I'm so silly 😜
That worked! Didn't realise it was caps sensitive lol.
Thank you so much! No more error message and the shop now works fine.
Seriously I want to thank everyone who posted in this forum for going out of their way to help me!
Thanks Pixie for updating the tutorial (the pictures and the example really helped!)
And thanks Mrangel for finding the problem!


95% of the time, an error in/with code, is just some stupid small simple mistake/typo, the problem is finding it, though...


I show items for sale in shops in the places and objects panel. This allows the player to look at them for a description. When player enters a shop, I remove the command bar and use printed buy commands on page or display buy verbs on the objects. This stops taking/stealing. Then return command bar after leaving shop.

It feels acceptable to have a gamebook looking page for shops. You are there for one reason anyway and it speeds up the process so you can get back to the fun. 🤓


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

Support

Forums