Log In  

It would be helpful if calling color() to change the default color would return the previously default color. I am currently using a snippet like this to restore a previous default color:

 t=band(peek(24357),15)
 color(c)
 blah blah
 color(t)
P#72338 2020-01-28 06:39

Further, if color() didn't actually do color(0) we could use it JUST to check the color without changing it!

P#72339 2020-01-28 06:40

Zep has said on Twitter that the next version (0.1.12) would have this behaviour, as well as pal(), cursor() and several others.

P#72341 2020-01-28 07:50
1

Could write a function I suppose:

-- push me pull you colors
-- written by dw817 (01-28-20)

function _init()

colt={}

-- maximum # of colors to
-- remember.
cstack=32

cls()

for z=0,3 do

for i=0,15 do
  colr(rnd(15)+1)
  rectfill(i*8,60,i*8+6,63)
end

repeat
  flip()
until btnp()>0

for i=15,0,-1 do
  colr(-1)
  rectfill(i*8,65,i*8+6,68)
end

repeat
  flip()
until btnp()>0

end

end

function colr(n)
local c=colt[#colt]
  if n>=0 then
    color(n)
    if #colt==cstack then
      del(colt,colt[1])
    end
    add(colt,n)
  else
    color(c)
    del(colt,c)
  end
end
P#72353 2020-01-28 18:31 ( Edited 2020-01-28 18:37)
1

While I agree that the API should do this by default for all state-setting calls, for the time being you should remember that you can replace the API if you want to, e.g.:

hooked_color=color
function color(...)
  local t=peek(24357)
  hooked_color(...)
  return t
end

(Note that "..." is a Lua language feature for argument forwarding, and not just my own shorthand.)

Also, no need to band(,15). The value in 24357 is exactly the one passed into color(). The upper 4 bits are only nonzero if you set them nonzero yourself, e.g. 0xb8 for red/green xmas patterns. You'd want to preserve them and not mask them off.

P#72859 2020-02-07 03:22 ( Edited 2020-02-07 03:31)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 20:59:54 | 0.007s | Q:16