Fset
- Sets the value of a flag of a sprite.
- n
-
- The sprite number.
- f
-
- The flag index (0-7). If omitted, a bit field of all flags is returned.
- v
-
- The value, either
true
orfalse
if the flag index is specified, or the bit field of all flags if it is not.
- The value, either
Each sprite has eight flags that can be set in the sprite editor or by the fset() function. You can use these flags for any purpose. One possible purpose is to define "layers" of map tiles, which modifies the behavior of the map() function.
To set a specific flag, specify the flag index as the second argument, and either true
or false
as the value. Flags are numbered from 0 to 7, appearing left to right in the sprite editor.
When fset()
is called without a flag index, it accepts a number that represents all of the flags. This is a bit field where flag 0 is the "least significant" bit: flag 0 (leftmost) has a value of 1, flag 1 has a value of 2, flag 2 has a value of 4, and so on, up to flag 7 with a value of 128.
Setting a flag changes the data in memory, but does not change the cartridge. A program can restore the original data from the cartridge with reload(), and can save the modified data to the cart with cstore(). See Memory for information about the memory addresses to use.
Examples
-- Set flag 0 (leftmost) of sprite 16.
fset(16, 0, true)
-- Clear flag 7 (rightmost) of sprite 16.
fset(16, 7, false)
-- Set flags 0, 1, and 7 of sprite 16.
fset(16, 131) -- 131 = 1 + 2 + 128