Accessing/changing variable in a module

HimmDawg

Warper
Member
Joined
Sep 28, 2019
Messages
2
Reaction score
0
First Language
German
Primarily Uses
RMVXA
Hey there.
For my game I wanted to have text sounds when the characters are displayed. For that purpose I use a script from Zerbu (https://www.rpgmakercentral.com/topic/607-text-sound-effect-updated/) because I'm fairly new to Ruby. It works perfectly but now I want to change the text sound via an in-game event. I hope it's okay if I post a fraction of the code here for reference:
Code:
module Text_Sound_Effect

  MESSAGE_SOUND = RPG::SE.new("Knock", 50, 70)
 
  MESSAGE_SOUND_FRAMES = 3
 
  MESSAGE_SOUND_DISABLE = 94
end
So I tried several things:
  • first I tried to simply call it via "Text_Sound_Effect.MESSAGE_SOUND = ..." but this didn't work because it is handled as a constant or something like that
  • I then researched a bit and tried to write a class containing the variable and calling this variable from the module and my in-game event. I'm not 100% sure anymore but I think the engine then said that my variable name is not a method
  • so I tried to write a method within the class to change the variable from outside. That didn't work for me either.
I also bumped into classes with self.method stuff but I was kinda lost there. So maybe somebody could help me out here =)
 
Last edited:

Kes

Global Moderators
Global Mod
Joined
Aug 3, 2012
Messages
21,382
Reaction score
10,824
First Language
English
Primarily Uses
RMVXA
@HimmDawg I think this is best in Script Support as you want help to adapt a script to your needs. Please edit your post to include a link to the web page where you got the script so that if people need to check something before offering a suggestion they won't have to go hunting around the internet.

I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
4,623
Reaction score
5,259
First Language
Indonesian
Primarily Uses
RMVXA
There are two approaches.

The first approach is to change the parameter. You can not change the value of the constant, but you can change its attribute.
For example, you can use this script call
Code:
Text_Sound_Effect::MESSAGE_SOUND.name = "new SE name"
Text_Sound_Effect::MESSAGE_SOUND.vol = 80
Text_Sound_Effect::MESSAGE_SOUND.pitch = 180
You don't have to edit the script to make it works, just script call.
However, it will not be saved, means if you restart the game, your change will also reset.

The second approach is to edit the script to include it in a save content. Add this at the bottom of the script or a new script slot.
Code:
class Game_System
  def msg_sound
    @msg_sound ||= Text_Sound_Effect::MESSAGE_SOUND.clone
  end
end
Then change line 41 which is
Code:
MESSAGE_SOUND.play
to
Code:
$game_system.msg_sound.play
You can also change the attribute the same way
Code:
$game_system.msg_sound.name = "new SE name"
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

So the overhaul on my project has been going great, I like this version of the project a lot more. It's more contained and less overly ambitious for what I can achieve given my constraints on time, money, and skills in advanced programming. I'm going to wait till my project is mostly finished to begin working UI polish again. I'm going to learn how to use LUNA MV to polish the project.
last time i used this site i was a different gender.. wow rlly makes u think... anyway transing ur gender is pretty cool and theres hair growing on my feet now 10/10
I should have listened to RPGMAKER Meme thread. I should have backed up my data. The Orphan of Time, my WIP, is completely gone, all those hours of work are completely gone :(
God what was my life before smartphones (I had a grandma's phone before wednesday)
Stream will be live shortly with The Witcher 3! Feel free to drop by!

Forum statistics

Threads
93,381
Messages
911,847
Members
122,883
Latest member
TEKILAO
Top