# Confused why draw code is clearing, pico-8 api demo

In the API demo when they do the example of how to draw a colour pallette at the top of the screen: I notice the commands don't work when used inside the draw function. When used inside of draw they showup for a second and disappear. removing the cls() allows them to stay, but I need cls included. What do i need to be doing to get the pallette to stay while using the following within the draw function?

function _draw()
cls()
rectfill(1,1,7,7,5)
for i=0,10 do
print(i,x,2,i)
x = x + 6
end
end


I can't find the API demo you were looking at to get that code. But here's how to fix the code you wrote so that it does what I think you want it to.

First, make sure you set the variable X somewhere before the FOR loop.

Second, there are 16 colors ( zero through fifteen ) so the FOR loop should start at 0 and end at 15.

Third, each number/letter is 3 pixels wide so adding 6 to X works for numbers 0 - 9 but double digits begin to overlap so increasing it to X=X+8 works well.

Fourth, the rectangle is there, I assume, to make the zero color (black) visible. But it can be better positioned around the zero by changing the x-axis variables of the RECTFILL.

CODE:

function _draw()
cls()
rectfill(0,1,4,7,5)
x=1
for i=0,15 do
print(i,x,2,i)
x = x + 8
end
end


RUN: