Log In  

Cart #cds-1 | 2019-10-04 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Hmm ... You press ENTER in the BBS and it pauses, okay, run it local or use the spacebar instead.

Also, use the "=" as the backspace key and the "[" key for letter P.

As you know or should by watching how to write game in Pico-8 or doing so yourself, there is a nifty function called FGET() which will let you retrieve whether or not up to 8-flags are being set for a sprite of your choosing.

You can see pointing right at them HERE.

So how do they work ? Very simply. You click on them, up to 8 and using the command FGET followed by the sprite # you get the value of TRUE or FALSE whether or not that particular flag # (0-7) is set.

Not bad, but it could be better. That's where I come in with my new code. :)

So what does it do ?

Well for one thing is it lets you add a lot more definition and ease of retrieval for your sprites.

For instance, here is the string generated by the builder. You don't need to modify the string manually as I've created a program to edit each individual sprite, but it's still important to see what it looks like:


The data is separated into 3-parts. The first is the sprite # to contain this special data. The next is the name of the sprite, up to 8-chars you remember. The next is any sprite flags that exist for that sprite, and there can be up to 52 in any order for each sprite. You will see some of them have "W" set meaning Wall. So while you can name the sprites anything you want, you can also individually switch on and off the 52-flags available for them.

So what are the 52-flags ? That would be these:

.!?,;:#$%&-+*/=()<>{}|~^[email protected]

Assume in Pico-8 that these are uppercase. Why no digits ? Because if you call FFGET() with digits it assumes that you are requesting either the text name or status of the flags based on your numeric entry. Let's continue.

Now run the program above and select a sprite with the arrow keys, press ENTER and you can enter an up to 8-character name for it.

Press ENTER again and you can hit any of those characters you see below and that becomes a flag. This would be real nightmare to do with numbers and a modified FGET() though, right ?

Not to worry.

You see, the way I set it, you can retrieve all the following:

ANSWER: text name of that sprite.
ANSWER: number of that sprite on the sheet, zero being the first.
PRINT FFGET(1st character of name)
ANSWER: also the same number

Let's pause for a second. That last one is a little tricky. If you have more than one sprite that you have named with the same beginning character, it will only choose the last one calculated. It's not a reliable method if you have more than 26-sprites and you should choose the full-name or number each time in your code if you have dozens of sprites with definitions. Okay, let's continue. How are the flags handled ? Quite simply.

PRINT FFGET(number),(number)
ANSWER: the condition of whether that sprite #'s flag # is TRUE or FALSE
PRINT FFGET(name),(number)
ANSWER: same as above
PRINT FFGET(number),(single string character of flag)
ANSWER: same as above
PRINT FFGET(name),(string character of flag)
ANSWER: same as above

Let's see this in action with the sprite, WALL.

Quite a bit is happening, first off the total number of sprites (range) is 63 by printing SPR_TOTAL.

Then we are printing SPR_FLAGCHARS which are the 52-choices available to set flags for that individual sprite, ON or OFF, TRUE or FALSE.

Next is SPR_FLAGS which as described above is the string you need to copy to your code to have these flags set for your sprites.

Now we're using FFGET(). The wall is sprite #3. 48 is the letter "W" from the table. And you can see how it's possible to mix and match them quite thoroughly and still get the results you want.

If you only have one argument for FFGET() though, if it's a number it will retrieve the name of the sprite. If it's the name it will reverse and give you the number.

Example, to plot the player:

provided you only have one sprite name that begins with "p"

And that's it !

For your use, IMPORT your own sprite table. Run the program. Set your flags. Press "\" to save to clipboard. In a separate PICO-8 task (you should have 2 running). PASTE that string at the top of your _INIT() code. Then copy that one line in the first cart, the one called SPR_INIT(). Call that from your _INIT() code.

And you're done !

This is a considerably more robust flag system than PICO-8 came with. This demo also uses 1% of your onboard memory so it should work fine for you. I hope you use it and if you do, please let me know. Would love to see how you are getting on it.

And yes, those sprites included - I plan to make a game sometime later demonstrating the use of this new sprite library so no borrowing them for your projects just yet. :)

If you have any questions, and you might as this is a pretty busy upgrade going on here, feel free to let me know.

P#68427 2019-10-04 00:21 ( Edited 2019-10-04 03:45)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-05-31 04:39 | 0.033s | 4194k | Q:28