Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of how to use "app.command.MoveMask"? #3

Open
Dakkers opened this issue May 12, 2019 · 9 comments

Comments

Projects
None yet
3 participants
@Dakkers
Copy link

commented May 12, 2019

I'm trying to create a "parallax" script that would take a layer, create X frames for this layer, and move the content in the cell in a direction by a small number of pixels per frame. I'm able to create the X frames correctly, but I can't get the content to move. Here's my code so far:

local spr = app.activeSprite

if not spr then
  app.alert("There is no sprite to export")
  return
end

local num_frames = 4
local vertical_drift = 2
local horizontal_drift = 0

for frame_i = 1, num_frames - 1 do
  spr.selection:select(Rectangle(0, 0, spr.width, spr.height))

  app.command.CopyMerged()
  app.command.NewFrame()
  app.command.Paste()

  spr.selection:deselect()

  local s = Selection(Rectangle(0, 0, spr.width, spr.height))

  app.command.MoveMask(
    s,
    "up",
    "pixel",
    vertical_drift
  )

  s:deselect()
end

The current behaviour: the content does not move at all, in any direction for any amount.

I have tried doing app.activeCel.position = ..., and also spr.selection.bounds = ... but those didn't work either. Can someone give me guidance? 😄

@jjhaggar

This comment has been minimized.

Copy link

commented May 12, 2019

I tried asking something the same on the community help forums some weeks ago, but no luck either ^^U
https://community.aseprite.org/t/lua-scripting-can-you-move-a-selection/2773
If I learn how to use MoveMask command I'll write it there, and here as well :)
Please let me know if you succeed at it first! ;)

@dacap

This comment has been minimized.

Copy link
Member

commented Jun 29, 2019

Last time I check the MoveMask wasn't working from scripts. I'll try to fix it for the next version if it's possible to do it quickly (as next week I'd like to release a patch for some important fixes).

@jjhaggar

This comment has been minimized.

Copy link

commented Jun 29, 2019

That would be great :D Thank you very much David! :D

@dacap

This comment has been minimized.

Copy link
Member

commented Jul 10, 2019

Here again, finally I was able to test a little the MoveMask command and create some documentation about it:

I think MoveMask will work only when the UI is available.

@jjhaggar

This comment has been minimized.

Copy link

commented Jul 10, 2019

Thanks a lot! :D

I was very hyped when I read that you were able to test and document the MoveMask command, but then I tested the example and it didn't work XD

So i thought, "I must be doing something wrong" and started checking and trying several things, after a while and when I was about to make a small video showing that it didn't worked for me just in case, I had an idea: "Mmmm... Maybe it's because of the quotes?" and yeah that was the problem XD

I'm using Windows 7 (Ultimate-64) and Aseprite v1.2.13-x64, and it seems that it doesn't like sigle quotes ', but if you use double quotes ", it works like a charm :D

So, I'd like to suggest you to test if it also does work on your usual OS (you were using Mac nowadays if I'm not mistaken?), and if it also works there, please replace the single quotes symbols by double quotes, so it'll work for everybody :)

-- Code with corrected quotation marks (for Windows 7 at least):

local spr = app.activeSprite
spr.selection = Selection(Rectangle(1,1,spr.width-2,spr.height-2))

app.command.MoveMask{
  direction="right",
  units="pixel",
  quantity=2
}

app.command.MoveMask{
  direction="up",
  units="pixel",
  quantity=2
}

app.command.DeselectMask()

Again, thank you very much David, you are the best! :D

@dacap

This comment has been minimized.

Copy link
Member

commented Jul 10, 2019

You're welcome @jjhaggar! I'll check that issue about the quotes on Windows later; it shouldn't differ between macOS vs Windows (because the Lua parser code is the same on both platforms), but I'll give a try.

Just in case, see if the copy-and-paste process of the code from the web browser to your text editor didn't mess the quotes (something that is really common on both platforms).

@jjhaggar

This comment has been minimized.

Copy link

commented Jul 10, 2019

I didn't copy-paste the text, I directly downloaded the raw file from here:
https://gist.githubusercontent.com/dacap/7be7102ea6845774e30d2d664dcfd964/raw/d49012f4cb89e7eb5d38145178be8e6dd1de931f/MoveMask%2520Test.lua
(I usually do that in order to avoid these kind of problems)

Maybe I have something installed that interferes with my Lua parser? I have no idea ^^U

@dacap

This comment has been minimized.

Copy link
Member

commented Jul 11, 2019

I didn't test on Windows yet, but I think it's related to other issue that I forgot in the Test.lua file: the target field (which is not initialized on the C++ code, so it's invalid at the very beginning).

I've updated the example.

@jjhaggar

This comment has been minimized.

Copy link

commented Jul 11, 2019

Oh, thank you so much! :D I was trying again today (using the double quotation marks) and it wasn't working, I was really confused XD

I have tried your updated example and it works perfectly! So the quotation type, single or double, seems to be irrelevant (I probably did something between one test and another, and it worked just by coincidence, and I thought it was the quotations).

Again, thank you very much!! :D :D :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.