Setting up a Shop (resolved)

So I started working on a new game and followed Pixies "Setting up a shop" tutorial. I love how well she explained the set up and it was pretty easy following her instruction. So, I had no doubt that I did it correctly. However, when I try to run the game I get the following error message at the start.
Error running script: Error compiling expression 'stock': Unknown object or variable 'stock'

If anyone can help me figure out what went wrong, that would be great. I can post the entire game code here if need be.


I think you'll need to post the code so we can spot the mistake. I'm guessing either 'stock' is the name of a parameter to a function, and maybe spelled wrong; or it could be the actual name of a stock room that's missing.


How do I paste the code? I do the 4 indents...and even tried the "surrounded with 3 backticks" it says I can't post that here.


That happens sometimes, nobody seems to know why. It's possibly part of the forum's spam filtering system. Sometimes it will just not allow a certain post. Often (but not always) one with code in; and often (but not always) a very long post.

Best I can suggest is using a site like pastebin, and posting a link here.


You need to use three backticks top and bottom: The back ticks are located on the button to the left of the [1] key

```
Then paste your code
```

It may be that it is already to large to post here. So I used the "Pastebin" as mrangel suggested.
here is the link:
https://pastebin.com/4pFM2QC4


there's some various quirks and filter/block system with the forum involved (if it's not just a post character max count limit as to the cause/reason for not being able to post), what always works for me is to add extra 'filler spam' at the top of my post:

for example, here's my post but it won't post (if first time) and/or update (if editing / if not first time):

blah
blah
blah
blah
blah

to fix this, all I do is this (I edit my posts a lot):

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

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

blah
blah
blah
blah
blah

if I try to edit it again with only a few character edits (or too quickly), it gets blocked by the system, as well:

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

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

blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah

so, to fix it again, I just add more 'filler spam' at the top of my post:

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

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

blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah

HK...did you not see the link to it that I posted above?
Here it is again:
https://pastebin.com/4pFM2QC4

Most of the stuff I have added in so far are objects and rooms not set up yet. So hopefully someone will be able to see what I am doing wrong.


oh, I just thought you also had a problem with posts not posting... I was addressing that... my bad


usually the mistake with new people is that they don't have their Values in double quotes, making them be Object (reference/pointer) Values, when they need to be String Values. You can try finding instance of 'stock' in your code, and try putting double quotes on it. For a quick way of seeing if this is the fix/error or not.

if not... we got more work for us.... in finding your error...


use the 'edit' menu bar's 'find' feature to search for 'stock'

you got some instances of 'stock' and 'Stock', quest IS case senstive, 'stock' and 'Stock' are completely different things

also look for possibly where 'stock' needs the double quotes, but doesn't have them...


for example:

lines 653 to 658:

<function name="SetUpShop" parameters="Shop, Stock">
    shop.stock = stock
    foreach (o, GetDirectChildren(stock)) {
      SetUpMerchandise (o)
    }
  </function>

you got a mismatch between 'stock' and 'Stock', change the 'Stock' to 'stock' (I think.. or do whatever you need to do as you understand your code's purpose more than I do):

<function name="SetUpShop" parameters="Shop, stock">
    shop.stock = stock
    foreach (o, GetDirectChildren(stock)) {
      SetUpMerchandise (o)
    }
  </function>

it looks like this might be your only error... let's hope...

(otherwise, you may also need a 'stock' or 'Stock' Object and/or a 'stock' or 'Stock' Attribute on an Object, which doesn't exist, and thus needs to be created)


P.S.

(I hate caps: upper and lower case usage, this is exactly why I never use them... if possible... lol --- either its due to my crappy finger-texting dexterity and/or I get confused in whether it needs to be upper case or lower case, lol)


Yes, that looks like the issue to me.

Your SetUpShop function has two parameters, named Shop and Stock (with capital letters). But in the code of that function you refer to them as shop and stock (without capitals).

Variable names have to be spelled exactly the same every time they are used. I think you should change the parameters list for that function so that they don't have capitals.

Also, in your start script, you have the line:

  SetUpShop (marketsquare, stockroom)

But the objects are named Market Square and StockRoom.
In that line, I think you will need to change the names so that they are spelled exactly the same as the name of two rooms. Exactly the same, in this case, means with the same capitalisation and the same spaces.


Excellent...that fixed it and now the shop works...However...When I buy an item...Now I get THIS Error:
Error running script: Error compiling expression 'player': Unknown object or variable 'player'


In Quest games by default, there is an object named player. In yours, there are two to choose from, playerM and playerF.

This means that instead of using the name player in code, you will have to use the attribute game.pov, which contains a reference to which object is currently the player. A lot of libraries and example code just assume the player is an object named player, so if you want to use those libraries, you'll probably have to search for every instance of player in their scripts and change it to game.pov.

In this case, the BuyObject function contains this line:

player.money = game.pov.money - BuyingPrice(obj)

which should be:

game.pov.money = game.pov.money - BuyingPrice(obj)

I so appreciate the help...it works perfectly now...Thank you both, so, so much!


as 'mrangel' points out.. if you renamed your 'player' Player Object to 'WHATEVER' Player Object, then you have to:

change all instances of 'player' to either: 'WHATEVER' or 'game.pov':

for examples

// from:
player.alias
// to:
WHATEVER.alias

// or:

// from:
player.alias
// to:
game.pov.alias


there's a good reason that lots of guides/libraries/code use 'player' in their code, as for new people, trying to explain to them about the 'game.pov' usage, can be very confusing for the new people to understand (and difficult for some of us to explain it), so that's why 'player' is used instead of 'game.pov', but as mrangel points out, there's the other side/issue in that if someone does rename their Player Object, then you got coding errors when using that library/code. There's pros and cons to both ways... sighs. And there's some nuances with using 'game.pov' vs not using it... though these nuances don't come up for most people's games (unless they're making rpgs with party/team members and/or multiple switchable Player Objects in their games, and want some effects to be for all/any Player Objects, which would use the 'game.pov', and some effects only to be for certain/specific Player Objects, which would NOT use the 'game.pov')


quickly about the 'game.pov' Object (reference/pointer) Attribute (and the other special/built-in and non-special Object reference/pointer Attributes), using code:

<game name="NAME_OF_GAME">

  <attr name="pov" type="object">player_1</attr>

  <attr name="pov_objectlist_attribute" type="objectlist">

    <value>player_1</value>
    <value>player_2</value>

  </attr>

</game>

<object name="room">

  <inherit name="editor_room" />

</object>

<object name="player_1">

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

  <inherit name="player_type" />

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

  <attr name="weapon" type="object">katana</attr>

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

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

</object>

<object name="player_2">

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

  <inherit name="player_type" />

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

  <attr name="weapon" type="object">short_sword</attr>

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

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

</object>

<object name="orc">

  <inherit name="editor_object" />

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

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

  <attr name="attack" type="script">
    msg ("Orc Life: " + this.life)
    this.life = this.life - game.pov.weapon.damage
    msg ("You attack the orc")
    msg ("Orc Life: " + this.life)
  </attr>

</object>

<object name="katana">

  <inherit name="editor_object" />

  <attr name="damage" type="int">50</attr>

</object>

<object name="short_sword">

  <inherit name="editor_object" />

  <attr name="damage" type="int">5</attr>

</object>

<type name="player_type">

  <statusattributes type="stringdictionary">

    <item>

      <key>strength</key>
      <value>Strength: !</value>

    </item>

    <item>

      <key>intelligence</key>
      <value>Intelligence: !</value>

    </item>

  </statusattributes>

</type>

<verb>

  <pattern>attack</pattern>
  <property>attack</property>
  <defaultexpression>You can't attack that!</defaultexpression>

</verb>

<command name="change_pov_command">

  <pattern>changepov</value>

  <script>
    show menu ("Pov (Player)?", game.pov_objectlist_attribute, false) {
      game.pov = result
    }

  </script>

</command>

<command name="strength_command">

  <pattern>strength</value>

  <script>

    game.pov.strength = game.pov.strength + 5

  </script>

</command>

<command name="intelligence_command">

  <pattern>intelligence</value>

  <script>

    if (game.pov.name = "player_2") {
      game.pov.intelligence = game.pov.intelligence + 3
    }

  </script>

</command>

Log in to post a reply.

Support

Forums