Help - Search - Members - Calendar
Full Version: controling variable in script
RPG RPG Revolution Forums > Scripting > Script Development and Support > RGSS
Mazel
Ummm... hello,,
Do anyone have any idea of how to put variable in script.
I wanna make a discount shop, my simple plan is adding the variable that controlled outside the script but will affect the script.
New Price = A (item price) / B (variable value) * 100
but I can't do that. *looks like it's not as simple as I thought ohmy.gif *
the game always went error, help me please....
using $game_variables[B] completely the only thing I can do, but it's not the answer
Redd
Moving to RGSS Script Support
Moonpearl
QUOTE
the game always went error, help me please....

No script + no error message = no help.

How can you possibly expect for someone to correct something they can't even see?
Night_Runner
QUOTE
How can you possibly expect for someone to correct something they can't even see?


Challenge accepted.

Night_Runner's Variable Prices Script
CODE
#==============================================================================
# ** Night_Runner's Variable Price's Script
#------------------------------------------------------------------------------
# History:
#  Date Created: 05/Jun/11
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=49690
#
# Description:
#  This script is designed to change the price of items, following a in-game
#  variable. If the variable is at 20, the the price will be 20% of
#  the original cost, etc.
#
# How to Install:
#  Select and copy this entire peice of code.
#  In your game, select Tools >> Script Editor
#  Along the left hand side, scroll all the way to the bottom, right
#   click on 'Main', and select 'Insert'.
#  Paste the code in the blank window on the right.
#
# How to Use:
#  On line xx defines which variable to follow, so be default it will follow
#  the in-game variable #10. When the in-game variable is set to 200, then
#  all items, weapons and armors will be 200% of the normal price.
#==============================================================================



#==============================================================================
# ** RPG
#------------------------------------------------------------------------------
#  Edited to allow variable prices
#==============================================================================

module RPG
  #--------------------------------------------------------------------------
  # * Invariables
  #--------------------------------------------------------------------------
  PRICE_MODIFIER_VARIABLE = 10  # Price follows variable #10 by default
  #==========================================================================
==
  # ** Item
  #----------------------------------------------------------------------------
  #  Edited to have a variable price
  #==========================================================================
==
  class Item
    #------------------------------------------------------------------------
    # * Price
    #------------------------------------------------------------------------
    def price
      return @price * $game_variables[PRICE_MODIFIER_VARIABLE] / 100
    end
  end
  #==========================================================================
==
  # ** Weapon
  #----------------------------------------------------------------------------
  #  Edited to have a variable price
  #==========================================================================
==
  class Weapon
    #------------------------------------------------------------------------
    # * Price
    #------------------------------------------------------------------------
    def price
      return @price * $game_variables[PRICE_MODIFIER_VARIABLE] / 100
    end
  end
  #==========================================================================
==
  # ** Armor
  #----------------------------------------------------------------------------
  #  Edited to have a variable price
  #==========================================================================
==
  class Armor
    #------------------------------------------------------------------------
    # * Price
    #------------------------------------------------------------------------
    def price
      return @price * $game_variables[PRICE_MODIFIER_VARIABLE] / 100
    end
  end
end



#==============================================================================
# ** End of Script.
#==============================================================================


I can re-write the entire thing so it's correct smile.gif

That, and I'm guessing that variable B was set to 0...
Mazel
Thank you so much Night Runner .\(^o^)/
I really appreciate it, since I got really stressed to figure it out,

my script is totally awful, the last thing I wrote is :

CODE
# Buy process
        $game_party.lose_gold(@number_window.number *( @item.price*$game_variables[4]/100)


I just wanna the price changed when it's a buy command, I don't wanna losing any gold for selling.

so after many trial and error, I decide to give up on script and using event instead.

CODE
control variable: [0001:Gold] = Gold
control variable: [0005:disc] = 100
control variable: [0005:disc]/= Random No. (2...5)
Text: Today discount is \v[5]%!
    : Enjoy your shopping

Control Variable: [0002:Gold2]=Gold
Control Variable: [0003:Gold return]=variable[0001:Gold]
Control Variable: [0003:Gold return]-=variable[0002:Gold2]
Text: You've shop for \v[3] Gold
    : Here's your change, Sir
Control variable: [0003:Gold return]*=variable[0005:disc]
Control Variable: [0003:Gold return]/100
Change Gold: + Variable [0005:Gold return]
Text: Receive \v[3]Gold


But I forget one thing... it also have the access to sell menu! it decrease the value of gained gold, huwaahhh.... that's why I asked to this forum, looking for some working script. I'm really glad Night Runner answer it. And thanks for allowing me to copy paste it ^^. Yesh!

Hiks, why do scripting isn't as easy as it look like >______<,,,
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.