So I’m trying to make a randomizer for the game PC Building Simulator. The problem is that not all parts are compatible with each other. I have this so far:

internals // this is ran silently above the title to init all variables because Perchance is kinda weird in its interpretation of the "code"
  [make_magic()] // [selected_case = mini_itx_case ? ]

output
  [case_compatibilities[case_size]]

case_sizes
  cube
  full_tower
  micro
  mid_tower
  open_frame
  super_tower

case_compats
  cube
    mini_itx_case
    micro_atx_case
    s_atx_case
  full_tower
    mini_itx_case
    micro_atx_case
    s_atx_case
    e_atx_case
    xl_atx_case
    ssi_eeb_case
  micro
    ...
  mid_tower
    ...
  open_frame
    ...
  super_tower
    ...

mini_itx_case
  cube
    CORSAIR Carbide Series Air 740
    CORSAIR Graphite Series 380T (Black)
    CORSAIR Graphite Series 380T (White)
    CORSAIR Graphite Series 380T (Yellow)
    InWin A1 (Black)
    InWin A1 (White)
    Lian Li TU150 (Black + Window)
    Lian Li TU150 (Black)
    Lian Li TU150 (Silver + Window)
    Lian Li TU150 (Silver)
    Raijintek OPHION
    Raijintek OPHION EVO
    Raijintek Thetis
  full_tower
    be quiet! Dark Base 900 (Black)
    be quiet! Dark Base 900 (Orange)
    be quiet! Dark Base 900 (Silver)
    be quiet! Dark Base Pro 900 rev. 2 (Black)
    be quiet! Dark Base Pro 900 rev. 2 (Orange)
    be quiet! Dark Base Pro 900 rev. 2 (Silver)
    Cooler Master COSMOS C700P
    Cooler Master MasterFrame 700 (Bench Mode)
    Cooler Master MasterFrame 700 (Showcase Mode)
    CORSAIR Obsidian Series 750D
    ...
  mid_tower
    ADATA XPG Battlecruiser (Black)
    ADATA XPG Battlecruiser (White)
    ADATA XPG Defender Pro (Black)
    ADATA XPG Defender Pro (White)
    Antec DF500
    Antec P110 Luce
    Antec P120 Crystal
    Antec P8
    ASUS ROG Strix Helios
    ...
  open_frame
    Open Benchtable OBT-BC1 (Black)
    Open Benchtable OBT-BC1 (Red)
    Open Benchtable OBT-BC1 (Silver)
    ...
  super_tower
    CORSAIR Obsidian Series 1000D
    CORSAIR Obsidian Series 900D
    ...
    
micro_atx_case
  cube
    CORSAIR Carbide Series Air 740
    Raijintek Thetis
  full_tower
    be quiet! Dark Base 900 (Orange)
    be quiet! Dark Base 900 (Silver)
    be quiet! Dark Base Pro 900 rev. 2 (Black)
    be quiet! Dark Base Pro 900 rev. 2 (Orange)
    be quiet! Dark Base Pro 900 rev. 2 (Silver)
    Cooler Master COSMOS C700P
    Cooler Master MasterFrame 700 (Bench Mode)
    Cooler Master MasterFrame 700 (Showcase Mode)
    CORSAIR Obsidian Series 750D
    ...

...



make_magic() =>
  mobo_size = mobo_sizes.selectOne
  case_size = case_sizes.selectOne
  sel_case = case_compats[case_size]
  return sel_case

I omitted a lot of stuff. My make_magic() function is fine. sel_case returns the name of one of the top-level lists (e.g. mini_itx_case or s_atx_case) which is great, but it is a string, not a reference to the list. How do I convert the string sel_case to an actual list reference?

  • perchance@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    1 month ago

    If sel_case is a string (i.e. the name of the top-level list that you want), then root[sel_case] will give you the actual reference to the list. The special root variable refers to the “top-level” / “root” node in your Perchance “tree” of lists/sub-lists.