After moving the selection with the “MoveMask” command, the following three scripts do not work correctly (no error occurs and nothing changes).
However, if I call the “DeselectMask” command, it will work correctly.
I think it’s probably a bug.
Change the selection by calling the Selection:select method.
local sprite = app.activeSprite
local bounds = Rectangle(0, 0, 10, 10)
sprite.selection:select(bounds)
app.command.MoveMask{
target='content',
direction='down',
units='pixel',
quantity=10,
wrap=false
}
-- app.command.DeselectMask{} --Uncommenting this line will make it work as expected
local newBounds = Rectangle(0, 0, 20, 20)
sprite.selection:select(newBounds) -- not working
Call the Selection:deselect method to deselect the selection.
local sprite = app.activeSprite
local bounds = Rectangle(0, 0, 10, 10)
sprite.selection:select(bounds)
app.command.MoveMask{
target='content',
direction='down',
units='pixel',
quantity=10,
wrap=false
}
sprite.selection:deselect() -- not working but app.command.DeselectMask is working
Assign a value to Selection.origin to move the selection.
local sprite = app.activeSprite
local bounds = Rectangle(0, 0, 10, 10)
sprite.selection:select(bounds)
app.command.MoveMask{
target='content',
direction='down',
units='pixel',
quantity=10,
wrap=false
}
-- app.command.DeselectMask{} --Uncommenting this line will make it work as expected
-- sprite.selection:select(bounds)
sprite.selection.origin = Point(0, 0) -- not working
I have just encountered this as well trying to write a script to shuffle some pixels around in 1.3.2 on linux using the installer version.
local spr = app.sprite
if not spr then return end
local sel = spr.selection
if sel.isEmpty then return end
local step = 2
local x = sel.bounds.x
local y = sel.bounds.y
local w = sel.bounds.w
local h = sel.bounds.h
app.transaction(
"Skew",
function()
for i = x, x + w - 1, step do
spr.selection:select(Rectangle({i, y, step, h}))
app.command.MoveMask {
target="content",
wrap=false,
direction="up",
units="pixel",
quantity=i / step
}
-- app.command.DeselectMask()
end
end)
Without the deselect mask command Aseprite just moves the first selection and crashes when I do any kind of operation on the sprite afterwards. Sometimes an error pops up just before the crash:
An error has occured.
Details:
Cannot modify the sprite.
It is being used by another command.
Try again.
Cannot modify the sprite when we are undoing/redoing an action.
Internal details:
- Message type: 12
- Editor state: N3app17MovingPixelsStateE
Unless I’m doing something fundamentally wrong I also think it’s a bug.
fyi, seems to still be an issue. (Second MoveMask doesnt work because selection isn’t updated. Adding the deselect fixes it:
local spr = app.activeSprite
if not spr then
app.alert("No active sprite.")
return
end
local sel = spr.selection
if sel.isEmpty then
app.alert("Make a selection first.")
return
end
local bounds = sel.bounds
--select the left half
local a = Rectangle(bounds.x, bounds.y, bounds.width / 2, bounds.height)
sel:select(a)
app.command.MoveMask {
target = "content",
direction = "up",
units = "pixel",
quantity = 10
}
--select the right half
local b = Rectangle(bounds.x + bounds.width / 2, bounds.y, bounds.width / 2, bounds.height)
sel:select(b)
app.command.MoveMask {
target = "content",
direction = "down",
units = "pixel",
quantity = 10
}