Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

gold script

after searching everywhere i realised that there is no way to change your gold in rpg maker. so im sure that most of you will use this too. i madea script to change the gold. this will make your games much more better. i am releasing it with the source code so that you can make the edits if you need to.

if you have ideas to add to it that will really make it better put them here and i will try to do them.


http://rapidshare.com/files/440172476/Project2.zip
 
So, I was curious. I downloaded your demo, and found a blank map with a tree trunk on layer one. You go to the tree trunk and press a, and nothing seems to happen. I checked out the event, and you used the default event command to add one gold to character's wallet. This got me curious, since you said you made a script to add gold, but you weren't using it.

So, I took a look at your scripts, and found this:

Code:
#this is my script if you use it you must credit me

class Gold

  def do_gold(amount, operation = 'do nothing')

    if operation == 'add'

      @gold = $game_party.gold

      @amount = amount

      $game_party.gold = @gold + @amount

    end

    if operation == 'subtract'

      @gold = $game_party.gold

      @amount = 0 - amount

      $game_party.gold = @gold + @amount

    end

    if operation == 'do nothing'

      @gold = $game_party.god

      @amount = amount

      $game_party.gold = @gold

    end

    @max_gold = 9999999

    if $game_party.gold >= @max_gold

      $game_party.gold = @max_gold

    end

  end

end

 

 

$goldscript = Gold.new

I think I'll let Bluescope get to you regarding globals, but I would like to point out that, as it is, it will crash when you leave the second argument ("operation = 'do nothing'") as the default, instead of setting it to 'add' or 'subtract'. That's because it makes your script look for $game_party.god, and I don't think that god is a part of that game's party.

Anyway, there are other issues, like the fact that this script is horribly incomplete, totally redundant, and needs to be mostly rewritten to optimize it.

That being said, I'm going to assume that you're new at scripting. Congrats on the effort, and I recommend that you take at least some of this advice to heart.
 
@Glitch: I actually downloaded it as well, but since like you I couldn't find anything special by just playing it, I got stuck at that point, as RMXP is still nonexistant on my PC ;)

@thirty: Since Glitch already pointed out the uselessness of the script, let me tell you how to chop the line count a bit... Line 1, for example, is completely uncalled for... trust us on that.

Wrapping the thing in a new class called Gold (and later assigning it to a global variable) is not only the harshest thing you could've done to me to wake me up right now, but also completely unnecessary. Here is what you should have done instead:
Code:
class Game_Party

  def do_gold

    # code

  end

end
This gets initialized by default, no need to explicitly call it, AND you can directly access your variables (like $game_party.gold --> @gold). Global variables are often an idicator where stuff really belongs to - if you have to call a variable from $game_party, it's likely that the whole method is Game_Party related - therefore, shove it in there in the first place.

What else is there... oh, one of my favourites: Method names. do_gold must be the shittiest method name I've seen in my life, along with make_effect and stash_stuff (which are made-up as well). If anything, you'd call it something along the lines of manage_gold, or change_gold_amount - yes, longer, but also a lot better understandable.

Your possibilities for operation are also kind of wonky... actually took me a few to realize what you're doing there at all, to find out that they really should be named 'add', 'subtract' and 'set'. I'd also recommend wrapping the conditionals for that into a case, like so:
Code:
case operation

when 'add'

  # do stuff

when 'subtract'

  # do stuff

when 'set'

  # do stuff

end

Now to the actual stuff you do upon deciding on the operation mode... setting an instance variable to the value of the local variable seems really strange - after all, you're staying inside the very same method all this time... same thing for $game_party.gold, which is actually very unnecessary to assign to another variable anyway, as you can access it from everywhere likewise.
As explaining you how to shorten that is a bit stressful, let me just show you how your script could've looked like if you followed all of my suggestions here:
[rgss]class Game_Party
  def manage_gold(amount, operation = 'add')
    case operation
    when 'add'
      $game_party.gold += [[amount, 9999999].min, 0].max
    when 'subtract'
      $game_party.gold -= [[amount, 9999999].min, 0].max
    when 'set'
      $game_party.gold = [[amount, 9999999].min, 0].max
    end
  end
end
[/rgss]
You can see I took the liberty and fixed the flaw of your script that allowed to set the gold to negative values... while decreasing the line count by another couple of lines on that.


Now here comes the fun part: All you have to do to do this completely without your script is create a Call Script, and if you want to increase the gold, copypaste the line that's under when 'add', so your Call Script looks like this:
Code:
$game_party.gold += [[amount, 9999999].min, 0].max

Credit me when you use this. :shades:
 
There is indeed no method of adding or subtracting gold in RGSS (not in the actual event commands), or at least that's what I found when I was messing around - I had to make a method similar to the above (but I think I just did it in Game_Party as Bluescope did, just not as nicely coded).
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top