Any idea how to make this code tighter?

Hey all,

Still cutting my teeth on the basics and while I have a major component working in my code, I’m hoping to tighten a few hundred lines of code into something more workable.

I’m using the newer material mapping from verse.assets.digest - it’s essential to my card game. But either because I’m too green to understand, since each material seems to be declared like a separate type, I’m wondering if it’s even possible to simplify this (it may not be?)

So I’ve got dozens of the following blocks with names like Mat_CBx:

    var Mat_CB1 : Card_Textures.Root_Materials.CB_Slot_1_material = Card_Textures.Root_Materials.CB_Slot_1_material{}
        var Mat_CB1_SpAb_Top : Card_Textures.Root_Materials.SpAb_Top_1_material = Card_Textures.Root_Materials.SpAb_Top_1_material{}
        var Mat_CB1_SpAb_Mid : Card_Textures.Root_Materials.SpAb_Middle_1_material = Card_Textures.Root_Materials.SpAb_Middle_1_material{}
        var Mat_CB1_SpAb_Btm : Card_Textures.Root_Materials.SpAb_Bottom_1_material = Card_Textures.Root_Materials.SpAb_Bottom_1_material{}
        var Mat_CB1_RX : Card_Textures.Root_Materials.RX_Slot_1_material = Card_Textures.Root_Materials.RX_Slot_1_material{}

name_subname_x_material are all connected to my device and creative_props later in the code…

A ton of my code is taken up by this… and I haven’t figured out any type casting on this sort of stuff - any ideas to make this code tighter, a.k.a. some sort of loop?

Thanks in advance.

1 Like

Are they just materials ? im having trouble reading it

2 Likes

Yeah, they’re materials that are referenced in Assets.Digest.

I tried creating a class or three that had something like

MyMats : material = material{}

and even

MyMats : material = Card_Textures.Root_Materials.CB_Slot_1_material{}

and nothing worked, I think it’s because how you have to append “_material” when referring to the assets.digest file… so I guess I have a specific ‘type’ for each of my 100+ material mappings?

Apologies, I know I’m not being terribly clear on this but it’s in large part because I’m still trying to get my bearings on calling materials this way and verse in general. Appreciate your perspective regardless.

1 Like

Why not just create an array of the materials then you can get/set materials at will ?

Maybe make the material names to begin with abit less lengthy

You could create a class and add all the material vars in it maybe ?

Unsure how a module would work on something like this? It might work abit like epics colors one

2 Likes

I’m not sure I understand that you need to make new material instances here ? Assuming you don’t, this would be a lot simpler

using { Card_Textures.Root_Materials }

Card_Textures<public> := module:
    Root_Materials<public> := module:

test_device := class(creative_device):

    OnBegin<override>()<suspends>:void=
        creative_prop{}.SetMaterial(CB_Slot_1)
1 Like

Thanks for the thoughts:

Tried that rather early on though I forgot the bug that it produced.

It’s on my list of things to do, but given the complexity of the project I’m kind of stuck with it. I mean it’s fine as is at the end of the day, I’m the only one going over the code, but I want to know better options going forward.

I’m already doing that in a few files for textures - I’m just connecting the materials here so I can swap out one of about 500 textures that are defined in mapped arrays in a variety of files.

Epic colors one? I’ll look that up, thanks.

1 Like

I’ll try this, but I think I need to make new material instances (not sure?).

I’ve got a hand of eight cards, each with 3 to 4 child materials on it, all of which need to be referenced separately for texture swapping:

…but that code snippet there could still be the ticket to reducing the clutter on this so will get back to you at some point / thanks a million.

1 Like

Its not clear what you actually trying to do ?

Ive watched the video 3 times and i still dont get it

I did something similar with a weapon selection menu ages ago but all i did was change the materials not teleport meshes ect

1 Like