Author Topic: fe.module_dir doesn't seem to work?  (Read 3355 times)

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
fe.module_dir doesn't seem to work?
« on: January 24, 2019, 03:28:36 PM »
Hi all. Is there some trick to getting fe.module_dir to work? Is it even a real thing? I don't see any reference to it in the front-end binding section on github, but I've seen it in other people's code. Is it something I have to assign? If so, what kinds of voodoo are involved? I have a shader in a module folder, but whenever I run my layout, I'm told it can't find the relevant file. If I move the shader file to the layout folder, it works, but in my module script, it's effectively ignored. What am I missing? Thanks for any help!

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: fe.module_dir doesn't seem to work?
« Reply #1 on: January 24, 2019, 03:55:20 PM »
Works for me. Please post a snippet of your code.

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: fe.module_dir doesn't seem to work?
« Reply #2 on: January 24, 2019, 04:35:40 PM »
Thanks for taking a look. I have a module under attract/modules/blurred-art In the module.nut file, I try to instantiate a shader that's in the same folder. I've tried variations of the following without success:

Code: [Select]
class BlurredArt {
    // Stuff
    constructor (...) {
        shaderA = fe.add_shader( Shader.Fragment, "gauss_kernsigma_o.glsl" ); // Doesn't work
        shaderB = fe.add_shader( Shader.Fragment, fe.module_dir + "gauss_kernsigma_o.glsl" ); // Doesn't work
        shaderC = fe.add_shader( Shader.Fragment, fe.module_dir + "blurred-art/" + "gauss_kernsigma_o.glsl" ); // Doesn't work
    }
}

The shader file is in the same folder (blurred-art) as the module.nut. Any ideas?

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: fe.module_dir doesn't seem to work?
« Reply #3 on: January 24, 2019, 05:32:50 PM »
You should start printing to the console as a way to debug.

If the class is creating the shader, it should be a relative directory. If your trying to use the shader outside your module, you need the module path to be passed to the layout.

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: fe.module_dir doesn't seem to work?
« Reply #4 on: January 24, 2019, 05:49:51 PM »
fwiw, I do print to the console...when I know what I'm looking for! :)

The module is what's creating and applying the shader, so just the shader name (fe.add_shader( Shader.Fragment, "gauss_kernsigma_o.glsl" );) should be all that's required? Yet that doesn't work. The console just tells me it can't find the shader in the layout "root." Which is confusing to me, because it's not supposed to be looking for it there.

The module is a wip. It does what I want (mostly) with the exception of finding the shader. I'm attaching it just for giggles.

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: fe.module_dir doesn't seem to work?
« Reply #5 on: January 24, 2019, 07:01:44 PM »
I looked at the code on my iPhone. It looks like it would work. Are you extending the class in your layout? Store your path as a variable within the module class. Print it within the module class, and within your layout. Let me know what the results of each is.

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: fe.module_dir doesn't seem to work?
« Reply #6 on: January 25, 2019, 06:43:24 AM »
Hi Keil,

Thanks to your suggestions, I discovered what I'd been doing wrong: I had both an older blurred-art.nut stand alone file in my modules folder as well as a blurred-art/ folder containing the relevant files. AM was looking at the first file instead of entering the folder. I must have dragged and dropped in the wrong place. Ugh. Such a simple mistake! Tracing the print output -- and realizing I wasn't getting anything no matter how many changes I made in module.nut -- got me looking in the right place. It's behaving like it should now! I greatly appreciate your advice!  8)

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: fe.module_dir doesn't seem to work?
« Reply #7 on: January 25, 2019, 02:37:01 PM »
No problem. That’s why I suggested print to terminal. I can write a whole class and make a simple mistake because zombies have an open skull sometimes. 😂