Script: "Buy & Sell Only" Issue

Started by Stray, September 02, 2012, 07:35:22 pm

Previous topic - Next topic

Stray

September 02, 2012, 07:35:22 pm Last Edit: September 02, 2012, 07:36:58 pm by Stray
I've got this script: http://rpgmaker.net/scripts/36/code/
It's made for shops where you can only buy or sell.

Just make an example game and try to make a shop where you only cat sell items.
Then, if you try to sell something, you'll get this message:
I'm very grateful to you all for your great help.

Lukas

Quote from: Stray on September 02, 2012, 07:35:22 pm
I've got this script: http://rpgmaker.net/scripts/36/code/
It's made for shops where you can only buy or sell.

Just make an example game and try to make a shop where you only cat sell items.
Then, if you try to sell something, you'll get this message:


maybe you need replace 'vend_desc' to 'sell_discount' ($game_temp.sell_discount).
because there is no 'vend_desc' in class Game_Temp.
Spoiler: ShowHide

This image been put in a spoiler because it's 2 MB which is above the size of images allowed in a spoiler.
Thank you for your understanding.
~Blizz



~Sorry :)

Memor-X

i'm not an expert in scripting but from a quick search, vend_desc is called as $game_temp.vend_desc, this means that vend_desc should be defined in $game_temp, based from the name it's gets a description of some sort but not sure what the  "vend" part of the name is supposed to be (i'm a firm believer that all functions and non-temp variables should be named which describes what they do, eg, item_desc() would return an item's description)

but the problem is that a description is a string and it's being multiplied to @item.price and then the result is divided by 2, the result i'm guessing is to show the value of an item for when you sell it (thus why your getting an error) so obviously vend_desc is not return a description but a number, i'm assuming it's calling variable rather than a function since it doesn't have () at the end (but from a lot of script i've read this can't be ignored if you don't use arguments.......bad and lazy programming in my eyes)

now, your actual error i know all to well, it pop up when you attempt to call a function which doesn't exist, as i said above, vend_desc should be defined in $game_temp however the only this script does in class Game_Temp is this


class Game_Temp
  attr_accessor :type                        # 2: Sell/1: Buy/0: Both
  attr_accessor :buy_discount                # Buy discount +- %
  attr_accessor :sell_discount               # Sell discount +- %
  attr_accessor :shop_interface                  # Sell discount +- % 
  alias gt_init initialize
  def initialize
      gt_init
      @type = 0
      @shop_interface = :default
      @buy_discount = 1
      @sell_discount = 1
  end
 
  # Return shop interface
  def act_shop_interface
    Wep::Shop_interfaces[$game_temp.shop_interface]
  end
end


there's no def vend_desc or attr_accessor :vend_desc to allow a call like $game_temp.vend_desc which means either 1 of 2 things

1) the person forgot to test this properly
2) the person forgot to say you need the SDK to use this script

i can give you a quick fix, see the code i pointed out, replace all of that with this code (search for class Game_Temp in this script, not in every script in the editor)


class Game_Temp
  attr_accessor :type                        # 2: Sell/1: Buy/0: Both
  attr_accessor :buy_discount                # Buy discount +- %
  attr_accessor :sell_discount               # Sell discount +- %
  attr_accessor :shop_interface                  # Sell discount +- % 
  attr_accessor :vend_desc
  alias gt_init initialize
  def initialize
      gt_init
      @type = 0
      @shop_interface = :default
      @buy_discount = 1
      @sell_discount = 1
      @vend_desc = 1
  end
 
  # Return shop interface
  def act_shop_interface
    Wep::Shop_interfaces[$game_temp.shop_interface]
  end
end


this should stop the error but the script may not work to how it should

Quote from: Lukas on September 02, 2012, 07:56:45 pm
maybe you need replace 'vend_desc' to 'sell_discount' ($game_temp.sell_discount).
because there is no 'vend_desc' in class Game_Temp.


if what Lukas says is right and vend_desc is supposed to be sell_discount then instead of using $game_temp.sell_discount after you put in my code use $game_temp.vend_desc, this can be done easily by using the follow Script Call in an event


value = 5 #whatever you wanted sell_discount to be
$game_temp.sell_discount = value
$game_temp.vend_desc = value


this way the 2 will have the same value so if Lukas is right, it'll work properly

i would suggest that it's better to ask the person who scripted this cause they would have a better understanding of their own code

Stray

September 02, 2012, 08:29:55 pm #3 Last Edit: September 02, 2012, 08:43:05 pm by Stray
Thank you very, very much for your extremely fast and extensive help!
It's working!
If there are any further problems, I'll post it here again.

P.S.:
Selling items with discount works (thankyou), but buying items with discounts sure is not working quite correct.
Because even if I haven't enough money, I can buy something with the discount price.
I'm very grateful to you all for your great help.

Lukas

descuento = (@item.price * $game_temp.vend_desc) / 2

descuento != english language,
maybe 'vend_desc' forgot to translatable
@item.price * $game_temp.vend_desc = 

This is sure to find a discounted price.... maybe..
Spoiler: ShowHide

This image been put in a spoiler because it's 2 MB which is above the size of images allowed in a spoiler.
Thank you for your understanding.
~Blizz



~Sorry :)

Memor-X

Quote from: Lukas on September 02, 2012, 08:31:50 pm
descuento = (@item.price * $game_temp.vend_desc) / 2

descuento != english language,
maybe 'vend_desc' forgot to translatable


didn't notice that......strange how all the comments are a lot of varibale names are in english and this isn't......would mean that you are right and 'vend_desc' is 'sell_discount' (now i'm seeing why "desc" is being used, it's normally short for description)

since "descuento" would probably mean "discount" then that would mean "vend" is supposed to be "sell", in all fairness vend_desc should be changed to sell_disc but i assume that the reason why that didn't happen was because it would look confusing (i still don't get what the dam difference is between Disc and Disk, is it stupid English difference between the US and UK like with colour = color and mum = mom)

ForeverZer0

The script was obviously translated from Spanish. Whoever did it just missed a few things.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Lukas

Quote from: Stray on September 02, 2012, 08:29:55 pm
P.S.:
Selling items with discount works (thankyou), but buying items with discounts sure is not working quite correct.
Because even if I haven't enough money, I can buy something with the discount price.

I didn't get it.
Spoiler: ShowHide

This image been put in a spoiler because it's 2 MB which is above the size of images allowed in a spoiler.
Thank you for your understanding.
~Blizz



~Sorry :)

Stray

September 03, 2012, 08:31:50 am #8 Last Edit: September 03, 2012, 09:16:40 am by Stray
Quote from: Lukas on September 02, 2012, 09:16:21 pm
Quote from: Stray on September 02, 2012, 08:29:55 pm
P.S.:
Selling items with discount works (thankyou), but buying items with discounts sure is not working quite correct.
Because even if I haven't enough money, I can buy something with the discount price.

I didn't get it.

If I buy an item with a discount-price, I can buy it, even if I don't have enough money.
For example I have 20 coins, but I can buy something what costs 21 or higher.


I am quite confused about what I am supposed to replace in the script now...
I'm very grateful to you all for your great help.

KK20

Locate this line within the script (around 717)
# If item is invalid, or price is higher than money possessed
if @item == nil or @item.price > $game_party.shop_gold

And do this to it:
# If item is invalid, or price is higher than money possessed
if @item == nil or @item.price * $game_temp.buy_discount > $game_party.shop_gold


The author didn't really do a good job making sure his script was well translated and documented. For example, he claims you can use $game_temp.gold_type in a script call, but there is no evidence of such a variable gold_type. The script exists here on CP, but he hasn't logged on since May.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Stray

Now it's working. You're epic guys, thank you!
Thankyou: ShowHide
I'm very grateful to you all for your great help.

Stray

June 04, 2013, 12:46:42 pm #11 Last Edit: June 04, 2013, 01:30:28 pm by Stray
New Prob:

If I use "sell", the items I have in my inventory aren't displayed. The sell category remains empty.


Is any switch occupied with a function in this script?
I'm very grateful to you all for your great help.