I need help.
billypaulhaley
19 Mar 2018, 03:53For some reason, quest doesnt realize that I set "bow" as a variable.
Code:
if (bow > money) {
msg ("You can't afford that!")
}
else if ((bow < money)) {
msg ("You now have a bow!")
DecreaseMoney (9)
money = 1
}
bow = 10
And it gives me this message: Unknown object or variable 'bow'

Anonynn
19 Mar 2018, 05:19I assume you're trying to do some kind of shop? If so...I would set it up like...
msg ("What would you like to do?")
menulist = Split("Buy;Sell", ";")
ShowMenu ("", menulist, true) {
if (result = "Buy") {
msg ("What would you like to buy?")
menulist = Split("Bow;Poopstick", ";")
ShowMenu ("", menulist, true) {
if (result="Bow") {
if (player.money>=10) {
msg ("Deal!")
}
else if (player.money<=9) {
msg ("No wai! You don't have enough!")
}
}
else if (result=Poopstick) {
msg ("No wai!")
}
}
else if (result = "Sell") {
msg ("They begone peasant!")
}
}
See from the looks of your menu you are see if your bow is greater than your money. But I don't see any number variables to measure if it's greater or not. Maybe I'm not grasping what you're doing but just a thought!
Anonynn.
mrangel
19 Mar 2018, 10:58There are many different ways to set up shop systems. I won't get into that now, but looking at your code I'm wondering about the line bow = 10
at the end. Are you intending to change the value of bow
afterwards, regardless of whether they could afford the old price or not?
Variables are local. Once you create them, they exist until the end of that script. So if you've previously set this variable in a different script, it won't exist any more. If you're intending the line bow = 10
to set the price, then you need to put it before the if statement that uses that variable.
billypaulhaley
19 Mar 2018, 15:31Your code doesnt work, im getting errors over here
billypaulhaley
19 Mar 2018, 15:50I fixed it myself by using this instead.
if (player.money>=5) {
MoveObject (fruit, player)
DecreaseMoney (5)
}
else if (player.money<=5) {
msg ("You can't afford that.")
}

Anonynn
19 Mar 2018, 20:44Oh, yeah. You couldn't directly use my code unless you had your objects listed the same way and the correct variables already in your game x) It was just an example. But if you got it working, excellent! I think it's just easier to do it this way instead of your first way.
Also always make sure if you create an object like...
bow
that when you refer to it in your game, for example in your shop, you spell it the same way, always.
bow
Bow
bOw
BoW
^--- are all different.
Glad your problem was solved :D
Anonynn.
jmnevil54
19 Mar 2018, 20:51Every time I saw someone store a variable, it was something like:
player.bow1 = 10
bow = player.bow1
Looks ridiculous, but that's how it was done.
hegemonkhan
19 Mar 2018, 20:53see this guide on using Attributes and the 'if' Script:
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
the 'name' is the ID for quest, so all names but be unique, so spelling must be exact, as a 'bow' is not the same as a 'Bow', 'money' is not the same as 'Money'
also, you want to be using 'Attribute' VARIABLES, so/as that means:
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE
or
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION
for (solely/fully as a scripting) example:
create ("bow") // the 'bow' needs to be an Object
bow.money = 10 // creating/adding/setting a 'money' Integer Attribute on/within/for the 'bow' Object, with an initial Integer Value of '10'
you can then use the 'bow.money' Integer Attribute where-ever you want (which is why you use 'Attribute' VARIABLES, as they're global VARIABLES)
then all the rest of the coding for 'buying/selling' and etc stuff involved with it for your game: see the example game code below
here's an example game (still haven't tested if quest requires the default 'author, version, and gameid' Attributes for the 'game' Game Settings Object, so aside from these being missing below, it's a full-working game, though it's for an older version of quest, and not for Pixie's most recent version of quest) for you:
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="example_game">
<attr name="shop_owner_cash" type="int">500</attr>
<attr name="katana_buy_price" type="int">100</attr>
<attr name="katana_sell_price" type="int">50</attr>
<statusattributes type="stringdictionary">
<item>
<key>shop_owner_cash</key>
<value>Shop Owner Cash: !</value>
</item>
<item>
<key>katana_buy_price</key>
<value>Katana Buy Price: !</value>
</item>
<item>
<key>katana_sell_price</key>
<value>Katana Sell Price: !</value>
</item>
</statusattributes>
</game>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="parent" type="object">shop</attr>
<attr name="cash" type="int">500</attr>
<statusattributes type="stringdictionary">
<item>
<key>cash</key>
<value>Player Cash: !</value>
</item>
</statusattributes>
</object>
<object name="shop_owner">
<inherit name="editor_object" />
<attr name="parent" type="object">shop</object>
<attr name="cash" type="int">500</attr>
<attr name="changedcash" type="script">
game.shop_owner_cash = shop_owner.cash
</attr>
</object>
<object name="shop">
<inherit name="editor_room" />
</object>
<object name="katana">
<inherit name="editor_object" />
<attr name="parent" type="object">shop</object>
<attr name="price" type="int">100</attr>
<attr name="buy" type="script">
<![CDATA[
if (katana.parent = shop) {
if (player.cash >= katana.price) {
player.cash = player.cash - katana.price
shop_owner.cash = shop_owner.cash + katana.price
katana.parent = player
msg ("You bought the katana from the shop owner")
} else {
msg ("You don't have enough cash to buy the katana from the shop owner")
}
} else {
msg ("The shop doesn't have a katana for you to buy from the shop owner")
}
]]>
</attr>
<attr name="sell" type="script">
<![CDATA[
if (katana.parent = player) {
if (shop_owner.cash >= katana.price / 2) {
shop_owner.cash = shop_owner.cash - katana.price / 2
player.cash = player.cash + katana.price / 2
katana.parent = shop
msg ("You sold the katana to the shop owner")
} else {
msg ("The shop owner don't have enough cash to buy the katana from you")
}
} else {
msg ("You don't have a katana for you to sell to the shop owner")
}
]]>
</attr>
</object>
<verb>
<property>buy</property>
<pattern>buy</pattern>
<defaultexpression>You can't buy that!</defaultexpression>
</verb>
<verb>
<property>sell</property>
<pattern>sell</pattern>
<defaultexpression>You can't sell that!</defaultexpression>
</verb>
</asl>