PDA

View Full Version : [HELP] Undocumented Function - Image.addLayerPaintStroke()



Alanrockid
August 3rd, 2025, 17:57
Hello! I need help figuring out the parameters for the Image.addLayerPaintStroke() function. It's not in the reference manual, but it can be found in the CoreRPG scripts and does exactly what I want: draw on an image layer.

From the only example in the ruleset, I was able to deduce that its parameters are:

Image.addLayerPaintStroke(node Image, Image Layer, Drawing Data)

The last one is a table with several parameters like Fill, Path, Stroke...

That's the problem. I can create a square, but the stroke doesn't appear. Checking the database, I can see that it did create the stroke, but its size is 0.0.

I have also tried to directly change the size in DB using DB.setValue(nodeImage, "size", "50,50") but with no success.

I need help figuring out how this function handles the tables and what the parameters are for strokes (or any other

Here is my function:



local nLayerID = Image.addLayer(nodeImage, "paint", { name = "Test Layer" })
if not nLayerID then return end

local tStrokeData = {
path = {
{ x=25, y=175 }, { x=525, y=175 },
{ x=525, y=625 }, { x=25, y=625 },
{ x=25, y=175 }
}
}
if bUseFill then
tStrokeData.fill = { color = sFillColor }
end
if bUseStroke then
tStrokeData.stroke = {
color = sStrokeColor,
size = "50,50"
-- size = {50,50}
-- size = 50,50
-- size = {w = 50, h = 50}
-- w = 50,
-- h = 50
}
end

Image.addLayerPaintStroke(nodeImage, nLayerID, tStrokeData)


The commented lines are other methods I tried with no success.

Any devs that can help me with that?

pindercarl
August 4th, 2025, 02:12
This should be the table format:

{
path = { { x = <number>, y = <number> }, ... },
stroke = { [asset = <string>], [color = <color>], [w = <number>, h = <number>], [angle = <number>], [fade = <number>], },
fill = { [asset = <string>], [color = <color>], [w = <number>, h = <number>], [angle = <number>], [fade = <number>] },
}

Alanrockid
August 4th, 2025, 04:27
This should be the table format:

{
path = { { x = <number>, y = <number> }, ... },
stroke = { [asset = <string>], [color = <color>], [w = <number>, h = <number>], [angle = <number>], [fade = <number>], },
fill = { [asset = <string>], [color = <color>], [w = <number>, h = <number>], [angle = <number>], [fade = <number>] },
}

Thank you very much for your reply! However, even with that info, the script continues to return a stroke with size 0,0 (according to db.xml). Am I missing something?

Here's the relevant code:



function onClickDown()
local nGridSize = 50
local sStrokeColor = "#a55b5bd1"
local nStrokeSize = 50
local sFillColor = "#FFFDFEFF"

local nodeImageRecord = DB.createChild("image")
if not nodeImageRecord then return end

DB.setValue(nodeImageRecord, "name", "string", "Test")
DB.setValue(nodeImageRecord, "image", "image", nodeImageRecord.getNodeName())

local nodeImage = DB.getChild(nodeImageRecord, "image")
if not nodeImage then return end

Image.setGridSize(nodeImage, nGridSize, nGridSize)

Debug.chat("Grid size is: ", Image.getGridSize(nodeImage))

local nLayerID = Image.addLayer(nodeImage, "paint", { name = "Square Layer" })
if not nLayerID then return end

local tStrokeData = {
path = {
{ x=25, y=175 }, { x=525, y=175 },
{ x=525, y=625 }, { x=25, y=625 },
{ x=25, y=175 }
},
stroke = {
color = "#a55b5bd1",
w = 50,
h = 50,
},
fill = {
color = sFillColor
}
}

Image.addLayerPaintStroke(nodeImage, nLayerID, tStrokeData)
end

pindercarl
August 4th, 2025, 12:42
Thank you very much for your reply! However, even with that info, the script continues to return a stroke with size 0,0 (according to db.xml). Am I missing something?

Here's the relevant code:



function onClickDown()
local nGridSize = 50
local sStrokeColor = "#a55b5bd1"
local nStrokeSize = 50
local sFillColor = "#FFFDFEFF"

local nodeImageRecord = DB.createChild("image")
if not nodeImageRecord then return end

DB.setValue(nodeImageRecord, "name", "string", "Test")
DB.setValue(nodeImageRecord, "image", "image", nodeImageRecord.getNodeName())

local nodeImage = DB.getChild(nodeImageRecord, "image")
if not nodeImage then return end

Image.setGridSize(nodeImage, nGridSize, nGridSize)

Debug.chat("Grid size is: ", Image.getGridSize(nodeImage))

local nLayerID = Image.addLayer(nodeImage, "paint", { name = "Square Layer" })
if not nLayerID then return end

local tStrokeData = {
path = {
{ x=25, y=175 }, { x=525, y=175 },
{ x=525, y=625 }, { x=25, y=625 },
{ x=25, y=175 }
},
stroke = {
color = "#a55b5bd1",
w = 50,
h = 50,
},
fill = {
color = sFillColor
}
}

Image.addLayerPaintStroke(nodeImage, nLayerID, tStrokeData)
end


Usually, when an API command is not documented, it is because it is in progress or incomplete and was added for internal use. This looks like this is an incomplete case. Looking at the API, it is expecting an asset to be defined for the stroke. I can add a note to take a look at improving the API, but I wouldn't expect the changes any time soon. A less good, temporary solution, would be to add a small white square image and pass that in as the asset.