Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> controling variable in script
Mazel
post Jun 22 2011, 09:26 AM
Post #1


Level 1
Group Icon

Group: Member
Posts: 7
Type: Writer
RM Skill: Beginner




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

This post has been edited by Mazel: Jun 22 2011, 09:27 AM
Go to the top of the page
 
+Quote Post
   
Redd
post Jun 22 2011, 07:40 PM
Post #2


:<
Group Icon

Group: Revolutionary
Posts: 2,315
Type: Developer
RM Skill: Advanced




Moving to RGSS Script Support


__________________________
Go to the top of the page
 
+Quote Post
   
Moonpearl
post Jun 22 2011, 11:59 PM
Post #3


Level 5
Group Icon

Group: Member
Posts: 73
Type: Developer
RM Skill: Advanced




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?


__________________________





Go to the top of the page
 
+Quote Post
   
Night_Runner
post Jun 23 2011, 12:26 AM
Post #4


Level 50
Group Icon

Group: +Gold Member
Posts: 1,528
Type: Scripter
RM Skill: Undisclosed




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...


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
Mazel
post Jun 23 2011, 04:27 AM
Post #5


Level 1
Group Icon

Group: Member
Posts: 7
Type: Writer
RM Skill: Beginner




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 >______<,,,
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 25th May 2013 - 06:14 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker