aesthetic question : Compilation module method

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Hi guys I was woundering when you do a module.....

exemple you call a configuration like a font comparaison

you will call like this : 

def draw_text_title @text = Sprite.new @text.z = 100 @text.bitmap = Bitmap.new(Graphics.width, Graphics.height) @text.bitmap.font.size = TITLE[:size] @text.bitmap.font.name = TITLE[:font] @text.bitmap.font.italic = TITLE[:italic] @text.bitmap.font.bold = TITLE[:bold] @text.bitmap.font.outline = TITLE[:outline] @text.x = TITLE[:x] @text.y = TITLE[:y] rect = Rect.new(0, 0, Graphics.width, Graphics.height / 2) @text.bitmap.draw_text(rect, $data_system.game_title, 1) endthis seem alright ...but if you take the TITLE module calling....if you call to much longer on the same line this will become a little unreadable no? 

like this exemple 

@title.amp = (Exemple[:wave],Exemple[:amplitude],Exemple[:speed])do you think this not a little big? I mean ....this not better to all stuck this kind of module call like this? 

def getting_module_information # System module information @file = SYSTEM[:bgm_name] @volume = SYSTEM[:bgm_volume] @pitch = SYSTEM[:bgm_pitch] # gameover logo module information @font_name = "" @font_size = "" end so in simple all the module information will be store in variable and in the SAME method.

the result in script!

def play_gameover_music # storing module information RPG::BGS.stop case SYSTEM[:me_or_bgm] when "BGM","bgm" return RPG::BGM.new(@file,@volume,@pitch).play when "ME","me" RPG::BGM.stop return $data_system.gameover_me.play end end Why ? simply this remove the fact you have to run all the script for know what configuration run what ! 

but this simply my opinion and please do not critique how I call my stuff (exemple SYSTEM[:ect]) this how luna engine do and I love this way because this clean and work great! 

I just want to know what you think of the module method and how you do your own way !

on this thanks for reading!
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Would I use a hash constant over storing them in instance variables and then referencing those variables instead of accessing the hash directly?

Maybe.

It provides a layer of abstraction that allows me to hide how I have decided to store my data so that if I decided a hash wasn't a good idea, I don't have to worry about breaking other people's scripts that assumed I used a hash.

module MyData Data = {} Data[:volume] = 120 Data[:pitch] = 100 def self.volume Data[:volume] end def self.pitch Data[:pitch] endendHere, I would recommend other scripters use the interface I have provided, rather than accessing the Data hash directly.They could of course say

MyData::Data[:volume]If they wanted to because nothing's stopping them, but if I decided to change :volume to :volume2 or something, they would need to update their own scripts.By providing an interface, it would increase compatibility in case of future changes.
 
Last edited by a moderator:

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,158
First Language
English
Primarily Uses
N/A
In this example I'd do this instead:

def settings SYSTEMenddef filename settings[:bgm_name]enddef volume settings[:bgm_volume]enddef pitch settings[:bgm_pitch]endSo that you can do this:

RPG::BGM.new(filename,volume,pitch).playThe benefit of the settings method is that if you change the settings class/module from SYSTEM to something else, you only need to change it once. It's not a necessary thing, but I like it tidy. The benefit of the remaining methods is overall readability, and I prefer to only use instance variables for things that will change; since things like settings in modules usually remaining constant, I believe it's better to not make them into variables because it can confuse the reader of the script on what is going on.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
I am not sure what you are asking.

Would I use a hash constant over storing them in instance variables and then referencing those variables instead of accessing the hash directly?

Maybe.

It provides a layer of abstraction that allows me to hide how I have decided to store my data so that if I decided a hash wasn't a good idea, I don't have to worry about breaking other people's scripts that assumed I used a hash.

module MyData Data = {} Data[:volume] = 120 Data[:pitch] = 100 def self.volume Data[:volume] end def self.pitch Data[:pitch] endendHere, I would recommend other scripters use the interface I have provided, rather than accessing the Data hash directly.They could of course say

MyData::Data[:volume]If they wanted to because nothing's stopping them, but if I decided to change :volume to :volume2 or something, they would need to update their own scripts.
this seem a really good idea I am tempted to follow this method but in same way galentmereth method seem also really interesting both have their own advantage in readability and their both problem like galent pointed 

In this example I'd do this instead:

def settings SYSTEMenddef filename settings[:bgm_name]enddef volume settings[:bgm_volume]enddef pitch settings[:bgm_pitch]endSo that you can do this:

RPG::BGM.new(filename,volume,pitch).playThe benefit of the settings method is that if you change the settings class/module from SYSTEM to something else, you only need to change it once. It's not a necessary thing, but I like it tidy. The benefit of the remaining methods is overall readability, and I prefer to only use instance variables for things that will change; since things like settings in modules usually remaining constant, I believe it's better to not make them into variables because it can confuse the reader of the script on what is going on.
you mark a point here! this seem even better for help and it's even more readable 

thanks for both answer this seem really logic the way you explain that and really easy! 
 

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

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top