RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Changing gold with event script

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 63
Rich... he come to town.
Hello,
I made a very simple banking system. Basically you can only carry so much at one time, so you have to keep depositing to keep earning, but both cash on hand and in the bank can be used at any time. In the Game_Party script I added some code to get this done and that works great but now I'm trying to make a Banker NPC so you can actually deposit your cash.

In the Game_Party script I added the following:
Code: [Select]
def deposit
  @bank = [[@bank + gold, 0].max, 9999999].min
  @gold = [[@gold - gold, 0].max, goldmax].min
end

But I can't figure out how to call this from the Banker event. I tried:
Code: [Select]
@game_party = Game_Party.new()
@game_party.deposit

Obviously this just makes a new instance of game_party that doesn't contain any information from the original game_party instance. Is there any way I can call deposit from the event? If not, are there other ways I can go about this? I don't want to use someone else's bank script so please don't say "Use Variables!" ... unless that's the only way  :P

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Best IRC Quote2014 Zero to Hero2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
The instance of Game_Party used without the game is $game_party. So you should use:
Code: [Select]
$game_party.deposit(gold)
where gold is an integer. You'll also have to adjust your deposit method to hold an argument to work properly.
Code: [Select]
def deposit(gold)
  etc
it's like a metaphor or something i don't know

**
Rep: +0/-0Level 63
Rich... he come to town.
Ah! Thank you. I've been working with C++ all my short life so Ruby is taking some getting used to. I'll have to look up what @ and $ mean I guess... along with everything else. Anyways, thanks again. This worked great  :)

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Best IRC Quote2014 Zero to Hero2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
I can tell you.
@ signifies an instance variable, meaning that it is accessible only through that instance of the class (i.e., that object). It can be accessed throughout the entire instance, but nowhere else unless made so.
$ is a global variable, it is accessible everywhere in the library. So if I did this:
Code: [Select]
class Whatever
  def initialize
    @thing = 2
  end
end
w = Whatever.new
p @thing # -> has no idea what you're talking about.
class Whatever
  def fix
    $thing = @thing
  end
end
p $thing # -> 2
class Whatever
  def something
    @thing += 1
  end
end
w.something # -> @thing = 3
w.fix # -> $thing = @thing
p $thing # -> 3
If that made any sense.
it's like a metaphor or something i don't know