Script window bounds aren't carried over

I’m having troubles with carrying over the dlg.bounds when reloading my script.
My hope is for the window not to snap in the middle of the screen every time I push a button. I don’t really care about its dimensions, but the position.
I’ve been tinkering with this problem on and off for the past few days, saving dlg.bounds to another variable, loading the variable upon reloading the script. And while it DID set dlg.bounds to the right value upon reloading, it doesn’t actually change the position or size of the window.
So I’ve ended up copying what another script was doing. As far as I can tell, I’m doing the exact same thing, down to the variable names.

Here is my script:

And here’s the one I’d like to plagiarize the bounds method from:

My function reloadColors(windowBounds) function acts basically the same way as domjohn’s function showColors(shadingColor, fg, bg, windowBounds) function, nesting the dialog so it can be reloaded.

Searching for bounds in both mine an his script, I have copied everything that looks relevant. But my script doesn’t work.

Pressing the reload button (close to the very end of my script) triggers the reload.
Similar to what most clickable things in domjohn’s script do.
Edit#1 - end

I should probably explain what my script is supposed to do when it’s finished if I’m already posting the whole thing.
I want to create a tool to generate gradients of colors. But I don’t simply want to do a linear interpolation of them. I want for instance to be able to do a standard linear RGB interpolation, followed by an interpolation of the saturation, value and alpha seperately and stitch it all together…
With it, you should for instance be able to distribute the distance between tones to effectively bake curvature into the used colors. Probably not that easy to see the point just from my explanation, but yeah.

I’m thankful for any help you can give me.

In the function definition you specify only one parameter:

function reloadColors(windowBounds)

But when you call it you pass two:

reloadColors(app.fgColor, dlg.bounds)

The color is passed as bounds, that’s why the window snaps back to the center - the color is not a correct type for dialog bounds and is ignored by the show method.


Oh my god! Thank you so much!
I didn’t know that the order mattered.
Now that I think about it, I’ve no reason to even pass the color.

I can’t thank you enough!

1 Like

Hi @Chaotic,

Some general advice I have is to

  1. take another look at the software you use to edit your scripts and
  2. try out the debugger that’s under File > Scripts in newer versions of Aseprite.

Above is a screen cap of Visual Studio Code. There are many alternatives. In the column on the left is a list of extensions available for download that help with Lua scripting. On the right you can see yellow underlines where the function bar is called, indicating there’s a problem.

The helpfulness of these extensions can vary quite a bit. For example, Aseprite userdata like Color creates false positives which are highlighted in yellow. For scripts I plan to use in the longer term, I’ve found that if I take extra time to help the extension, my time is repaid in less debugging:

Here is what the debugger looks like. There are two tabs/buttons on the bottom right, the locals tab shows the state of variables when foo is called; notice that c is nil.

If you prefer to debug your scripts using print, which I do sometimes, my understanding is that Lua uses a similar/same shorthand for string.format as C++ printf. So I bookmarked this reference.


Oh hey! I’m sorry I’m only reading this now, since I’ve taken a bit of a break and haven’t been on here in a couple of days!

What I’ve been using to write everything is Notepad++. I know that an IDE is better suited for my needs at this point and tried switching to my already installed IntelliJ. That switch didn’t last long, because I repeatedly ran into issues with formatting and introduced errors I wouldn’t have otherwise.

Maybe I won’t have these issues with Visual Studio Code! So thank you for the suggestion!!

Oh, I don’t know how I missed the debugger until now. That looks useful! Especially since I seem to keep running into nil values for various reasons and only notice them fairly late.

Also, thank you so much for your tutorials on making scripts for Aseprite. I thought of messaging you directly because of them, but didn’t know how to say thank you without being awkward!

1 Like