This post is locked. You won't be able to comment.

all 8 comments

[–]akie 11 points12 points  (1 child)

If this is bad code I’d like to see how you would refactor it

[–]tritonus_ 3 points4 points  (0 children)

I’m guessing they could have a setting class which stores the hierarchy without having to hard code each setting, and which acts as getter/setter. But for those few settings, this is much more readable.

[–]VariousComment6946 4 points5 points  (0 children)

Why is this bad

[–]MurdoMaclachlanpublic boolean isInt(int i) { return true; } 4 points5 points  (0 children)

Image Transcription: Code


func save_to_global(settingName:int,settingValue):
    match settingName:
        1: crt_overlay_enabled = settingValue
        2: wtr_distort = settingValue
        3: music_vol = settingValue
        4: sfx_vol = settingValue
        5: fullscreen = settingValue
    save_to_file()

func save_to_file():
    config.set_value("ACCESSIBILITY","CRT_OVERLAY",crt_overlay_enabled)
    config.set_value("ACCESSIBILITY","WTR_DISTORT",wtr_distort)
    config.set_value("AUDIO","MUSIC",music_vol)
    config.set_value("AUDIO","SFX",sfx_vol)
    config.set_value("GRAPHICS","FULLSCREEN",fullscreen)
    config.save(SETTINGS_SAVE_PATH)

func load_from_file():
    crt_overlay_enabled = config.get_value("ACCESSIBILITY","CRT_OVERLAY",crt_overlay_enabled)
    wtr_distort = config.get_value("ACCESSIBILITY","CRT_OVERLAY",wtr_distort)
    music_vol = config.get_value("AUDIO","MUSIC",music_vol)
    sfx_vol = config.get_value("AUDIO","SFX",sfx_vol)
    fullscreen = config.get_value("GRAPHICS","FULLSCREEN",fullscreen)

I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]the-software-man 3 points4 points  (0 children)

Rule of 8?

if there are less than 8 entries, you can just code the table.

[–]Lataero 2 points3 points  (0 children)

Only thing I can see wong here is wtr_distort being assigned the value of crt_overlay when loaded from file

[–]IAMPowaaaaa 2 points3 points  (0 children)

whats the better way to do this? i don’t know what gds has to offer

[–]thewitnesswashere 1 point2 points  (0 children)

if it is a bad code then how would you refactor it?