if(X >=51 and X <=52 and Y==1 and button ==1) then color = colors.red -- color changing code else colorIndexNumber = colorIndexNumber + 1 clickIndexTable[colorIndex] = X,Y,color -- sets the table index --[[ color index to where you clicked and the color, so if you clicked at 1,1 and the color is colors.green it sets click index table to 1,1,color, so at the end when it redraws what you made, it does for a=1,#clickIndexTable do paintutils.drawPixel(1,1,colors.red) end so, it should have done that, but it said expected X,Y and color. --]]
ApplePAINT Help.
Started by Gumball, Oct 21 2014 05:26 AM
2 replies to this topic
#1
Posted 21 October 2014 - 05:26 AM
Hi, im developing a paint program for my OS, AppleOS, but iv'e ran into a snag, I almost got a save function/ something that memorizes where you click and what color, but its not letting my. Heres the code I used. First, i'll explain the 3 variables. Color is a variable in my paint program that whenever you click a color button, it changes the color to something like colors.red, or colors.green . X and Y is just where you clicked.
#2
Posted 21 October 2014 - 11:52 AM
You're missing a lot of your code out here - not to mention the exact wording of the error - but I can at least tell you that this line won't do what you're thinking:
When it runs, clickIndexTable[colorIndex] will be set to the value of X. The values of Y and color won't be assigned to anything. See here as to why.
It appears what you're wanting to do is create a sub-table in clickIndexTable:
... and unpack its contents when calling paintutils.drawPixel() within your loop:
Personally, I'd use X and Y to determine the indexes within which to store the colour data:
This way you automatically overwrite old data about pixels which the user drew over more than once. It does limit potential for an undo function, however.
clickIndexTable[colorIndex] = X,Y,color -- sets the table index
When it runs, clickIndexTable[colorIndex] will be set to the value of X. The values of Y and color won't be assigned to anything. See here as to why.
It appears what you're wanting to do is create a sub-table in clickIndexTable:
clickIndexTable[colorIndex] = {X,Y,color} -- sets the table index
... and unpack its contents when calling paintutils.drawPixel() within your loop:
paintutils.drawPixel(unpack(clickIndexTable[a]))
Personally, I'd use X and Y to determine the indexes within which to store the colour data:
clickIndexTable[Y][X] = color -- sets the table index
.
.
.
for b = 1, table.maxn(clickIndexTable) do
for a = 1, table.maxn(clickIndexTable[b]) do
if clickIndexTable[b][a] then paintutils.drawPixel(a,b,clickIndexTable[b][a]) end
end
end
This way you automatically overwrite old data about pixels which the user drew over more than once. It does limit potential for an undo function, however.
#3
Posted 22 October 2014 - 05:37 AM
Thanks!
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











