? Random's Big Dumb Library ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Creep into the Halloween / Horror Programming Contest (Deadline Extended)

Random's Big Dumb Library

Submitted
Updated
Author
randomouscrap
Public Key
DX3EV3R4
Min. Compat.
All
Version
0.4
Size
44KB
Rating
12 votes
Description This is the library I'll use in my programs (if I ever make any). It's a collection of functions that provide:
  1. Prime number generation/detection
  2. Kinda fast dictionaries (associative arrays/arrays indexed by strings)
  3. Bit and byte vectors with automatic resizing
  4. LZS compression for GRPs (both slower and worse at compression than rei's, so it's useless)
  5. Various math functions
  6. Debug logger for outputting messages on top/bottom screen
  7. Functions for basic character movement around a map
  8. Textboxes
  9. Menus (built from textboxes)
  10. Sound effects
OK but seriously, it's not good. [url=https://www.youtube.com/watch?v=ZTeuFlkbtYM]https://www.youtube.com/watch?v=ZTeuFlkbtYM[/url] [url=https://www.youtube.com/watch?v=4lY3t_yYRVQ]https://www.youtube.com/watch?v=4lY3t_yYRVQ[/url] I don't want any credit if you use this library.
Instructions

How to use:

EXEC "PRG3:RNDLIBFULL" Run the above to make all functions available. You can make the slot whatever you like; it doesn't have to be 3.

Functions Available:

Prime Numbers:

ISPRIME(NUM) : determine if a number is prime (up to 16,383*) NEXTPRIME(NUM) : get the closest prime larger than NUM (up to 16,383*) PREVPRIME(NUM) : get the closest prime smaller than NUM (up to 16,383*) CACHEPRIMES NUM : generate the prime data for numbers up to NUM * = with default settings. Running CACHEPRIMES will change the upper range; for instance, CACHEPRIMES(100000) will change the upper bound to 100000 for ISPRIME, NEXTPRIME, and PREVPRIME Examples: ?ISPRIME(5) 'TRUE ?ISPRIME(200) 'FALSE ?NEXTPRIME(20) '23 ?NEXTPRIME(11) '13 ?PREVPRIME(10) '7 CACHEPRIMES 100000 'Takes a little bit ?ISPRIME(99999) ' FALSE

Bit/Byte Vectors

GETBIT(BIT,VECTOR%) : Get the bit (0 or 1) for the position BIT within the given bit vector* SETBIT BIT,VALUE%,VECTOR% : Set the bit for the position BIT to the value VALUE (0 or 1) within the given bit vector* GETBYTE(BYTE,VECTOR%) : Get the byte (0-255) for the position BYTE within the given byte vector* SETBYTE BYTE,VALUE%,VECTOR%) : Set the byte for the position BIT to the value VALUE (0-255) within the given byte vector* * = A bit/byte vector is just an integer array. You can use existing arrays; the data is treated as though it is packed. Examples: DIM V%[0] 'A bit/byte vector is just an integer array ?GETBIT(0,V%) '0 SETBIT 5,1,V% ?GETBIT(5,V%) '1 ?GETBYTE(65,V%) '0 SETBYTE 12,128,V% ?GETBYTE(12,V%) '128 ?GETBIT(103,V%) '1 (we set that bit with the previous SETBYTE)

Dictionary

DICCREATE$(INITIALSIZE) : Create a dictionary with the given initial capacity (can be 0) DICGET$(KEY$,DIC$) : Retrieve the value* from dictionary DIC$ at the given key (returns "" if key doesn't exist) DICSET KEY$,VALUE$,DIC$) : Set the value* for the given key in dictionary DIC$ (adds key if key doesn't exist yet. Increases capacity automatically if dictionary is getting full) DICHASKEY(KEY$,DIC$) : Return whether or not dictionary DIC$ has the given key. DICRESIZE DIC$,NEWSIZE : NOT NECESSARY TO CALL. Increase capacity to at LEAST given size. Will only increase dictionary size. Actual size set may be different. * = float and integer versions are available: DICGETI%, DICGETF#, DICSETI, DICSETF Examples: DIM D$[0] 'A dictionary is just a string array. D$=DICCREATE$(10) 'Set initial capacity to a large value for faster insertion. Resizes automatically regardless ?DICGET$("MYKEY",D$) 'Prints nothing DICSET "MYKEY","HIHI", D$ ?DICGET$("MYKEY",D$) 'Prints HIHI DICSETI "MONKEYS",53,D$ ?DICGETI%("MONKEYS",D$) 'Prints 53

Math Crap

DISTANCE(X1#,Y1#,X2#,Y2#) : Get the distance between two points CLOSESTMULTIPLE(NUM,MULT) : Get the closest number to NUM that is a multiple of MULT. LERP(A#,B#,T#) : Get the value for linear interpolation between A and B at point T. BLENDCOLORS(COL1,COL2,SHIFT#) : Blend two colors together. SHIFT# tells how much of the second color to add (0 is all the first color, 1 is all the second color, 0.5 is a perfect blend) BRIGHTENCOLOR(COL,AMT) : Brighten color by given amount. This is a linear shift: all channels are increased by the given amount. If the amount goes over 255, it is capped. BRIGHTENCOLORM(COL,M#) : Bright color by given multiple. This is much more like the "brightening" you would expect: each channel is scaled by the given amount, which keeps the overall color roughly the same. Use this version if you expect real brightening. SIGN(X) : Gives the sign of X. Returns 1 if X>0, -1 if X<0, and 0 if X==0. Examples: ?DISTANCE(1,2,2,2) '1 ?DISTANCE(1,1,2,3) '2.236... ?CLOSESTMULTIPLE(10,3) '9 ?CLOSESTMULTIPLE(12,5) '10 ?LERP(5,10,0.5) '7.5 ?BLENDCOLORS(&HFF00FF00,&HFFFF0000,0.5) ' &HFF777700 ?SIGN(-5) '-1 ?SIGN(5) '1

String Stuff

STRINGJOIN$(ARRAY$,JOINCHR$) : Join an array of strings together and place JOINCHR$ between them. STRINGSPLIT$(STRING$,DELIM$) : Split a string into an array using the given character as a delimiter. SARRAYTOSTRING$(ARRAY$) : Convert a string array into a single string. This can be used to turn dictionaries into single strings. STRINGTOARRAY$(STRING$) : Convert a string converted with SARRAYTOSTRING back into a string array. This can be used to unpack dictionaries (if you pack them into a single string with the above function). Examples: DIM A$[0] A$=STRINGSPLIT$("DATA1/DATA2/SOMETHING/WHATEVER","/") 'An array with 4 elements: DATA1, DATA2, SOMETHING, WHATEVER ?STRINGJOIN$(A$,"%") ' DATA1%DATA2%SOMETHING%WHATEVER

Simple Game Engine

I've only just started this thing, so it's bound to change a lot. For now, you can see an example of what's done by loading "TESTMOVE". You should see that the code is very short; everything is done in the call to SGEBASIC (simple game engine). I designed to be as modular as possible while still being fairly easy to actually use. Right now, the functionality is split up into:
  1. Speed Calculation
  2. Player position update
  3. Step calculation
  4. Background drawing
  5. Player drawing
Each of these functions can be easily replaced with your own function simply by changing the appropriate value in the dictionary. I'll explain it all later when it's actually done.

Textboxes

Textboxes are simple boxes which display formatted text with automatic line breaking and scrolling. They are drawn on the GRP layer of your choosing. They are nowhere near finished, but maybe they're a little usable... not really. Textboxes are HIGHLY customizable, so there's a lot of settings and it might get confusing. I'll add a wrapper around customization in the future so it's easier, but for now, I would stick with the default settings. Textboxes are OBJECTS, so you will need to create the textbox object, then pass that object around to all the functions. Keep this in mind when you're looking at the following examples: Examples: DIM TB$[0] TB$=TBCREATE$() 'DICSETF "CHRSCL",2.0,TB$ 'Uncomment this to see text scaling in action DIM TEXT$="Look at all this text that we're outputting to the screen! Too bad it's not enough to make it scroll." TBSHOW TB$ 'Draw textbox TBTEXT TBFIX$(TEXT$,TB$),TB$ 'Show text with automatically-inserted elements (such as the pause at the end) TBHIDE TB$ You can also load TESTTB to see a test program for textboxes.

Menus

Every game needs a menu somewhere. Most of the time, unless it's the MAIN menu, you're just selecting from a small set of choices. Why program this every time you need it when you can have an automatic menu that matches your textboxes? Menus work a lot like textboxes, except that they require more setup. Since they require more setup, I've created a "quick" function which does all the setup for you. Maybe one day I'll go over the ridiculous amount of customization, but for now, this'll have to do. Menus can be placed anywhere on the screen, HOWEVER, unlike textboxes, they can be "anchored" to a corner other than the top left. For instance, if you set the menu's X and Y to 0 and you specify the anchor as the bottom left, the 0,0 will now mean the bottom left. Menus can be anchored to any of the four corners; the default is the lower right (for use with textboxes). Furthermore, even though menus are built from textboxes, they will ignore their width, height, and text location settings since menus are automatically sized to fit the text they are displaying. Examples: DIM MN$[0] MN$=MENUCREATE$() DIM OPT$[0] PUSH OPT$,"Kittens" PUSH OPT$,"Puppies" PUSH OPT$,"Echidnas" PUSH OPT$,"Bunnies" DIM SELECTED=MENUQUICK(OPT$,MN$) IF SELECTED>=0 THEN PRINT "You've selected: "+OPT$[SELECTED] ELSE PRINT "You cancelled!" You can also load TESTMENU to see it in action. I use STRINGSPLIT to create the list of options in that program. I'll add the others later or something.
Notes

Changes:

0.4

  1. Dictionaries are now much faster and should keep their constant access time for much larger dictionaries. Dictionaries up to 1000 elements now have roughly the same access time as dictionaries with 100.
  2. Added menu system. Menus can be anchored to corners of the screen and use many of the same options as textboxes.
  3. Added string functions for splitting/joining/etc.

    0.3

    1. Made dictionary work for single character keys (it would crash before)
    2. Made dictionary lookup twice as fast for keys which resort to linear scan.
    3. Added the textbox library

    0.2

    1. Fixed dictionary functions so it actually hashes correctly now
    2. Added the beginnings of Simple Game Engine stuff.
    In the future, I want to add:
    1. Textbox wrapper functions so it's easier to use
    2. An RPG Library
Categories
Keywords
  • textbox
  • menu
  • stringsplit
  • stringjoin
  • prime
  • bit
  • byte
  • lerp
  • blend
  • dictionary
38 Comment(s) PetNet PetNet That' why back in the day they would teach us to put line increments of 10 so that we would have more space to add code later on (10,20,30,40,50,60). snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! Please use the reply button. It shows up when you hover your cursor over root comments on desktop, or tap them on mobile. I don't even know why we decided to hide them in the first place. PetNet PetNet Speaking of it not being compatible with other BASICS, I honestly wish that they kept the GOTO (line number) function instead of the GOTO(@LABEL) thing they have now. It just makes more sense, you wouldn't have to put tons of labels and you could say GOTO(LINE NUMBER) if you wanted to bypass some code in a group, whereas with labels you have to put ANOTHER label to bypass stuff. Lumage Lumage Head Admin Day Person I like the warm sunshine and wake up early! Express Yourself Gardening I like to garden! Hobbies Touhou Project Is Awesome! I love Touhou Project! Express Yourself And when you edit your code, you get to rewrite all your line jumps! Although there's an argument that you should not be writing your code in such a way that you need GOTO to jump around like described, the cost of adding a label is not so great that it makes GOTO line a helpful construct. snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! Reminder that you had to add your own line numbers, so they were just labels except on every line. Also I don't know what this has to do with this page. banana banana RNG Hidden Easter Eggs Disguised Hidden Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength there is a little error in textboxes a part says tbchrsize$ NateDogg1232 NateDogg1232 Night Person I like the quiet night and sleep late. Express Yourself Avatar Taboo I didn't change my avatar for 180 days Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength That can be fixed (as you may have already figured out) by taking off the $ from that function call. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS SB already has a sign function. Also: -array indexes are automatically rounded towards 0 -RGB automatically limits input values to between 0 and 255 randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies Wow... wow, it's called SGN instead of SIGN? Like... they have CEIL, why can't they have SIGN? They can't say "compatibility" because SB isn't even compatible with old BASICs. I don't trust that functionality to remain the same, so I'll stick with forcing it to be rounded down. I didn't know about DIV being integer division though, so I can do that. I also don't trust THAT functionality to remain the same. I would rather have slower functions with known results than faster functions that *MIGHT* not work in an update where they decide to use modulus instead of MAX. But thank you for the info! 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Also, I noticed you sometimes use #FALSE/#TRUE and sometimes FALSE/FALSE.... MAKE UP YOUR MIND!!!! randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies Hey that's YOUR fault! >:P You told me #TRUE and #FALSE were faster when I was in the middle of writing the library, so I switched over. Nobody's gonna use this thing anyway, so I'll just switch TRUE to #TRUE when I come across them. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS I think the speed difference is so small that it might be better to pick the one that you think looks nicer, rather than the one that's 0.00001% faster. snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! constants are faster but only by such a micron of difference you're better off dedicating optimization elsewhere. Like SGN. It's been called that since PTC, come on. Even if they DO make a new SB (probably wont) they're not gonna change it randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies I'm sorry, I was just mindlessly complaining. I just didn't see SGN in the reference because I was looking for SIGN. I should've looked harder. to4oo4 to4oo4 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Video Games I like to play video games! Hobbies Hail randomouscrap. mia mia Night Person I like the quiet night and sleep late. Express Yourself Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Please tell me the "main features" of the text-box library. randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies
  1. Animated show and hide (with sound effects)
  2. Automatic line break (but that's a given)
  3. Automatic break insertion at punctuation for longer text (if desired; default is false)
  4. Automatic smooth scrolling for text that's too large to fit in one textbox
  5. Insert commands within text to change color, speed, insert linebreaks, insert waits, and insert textbox breaks.
  6. Text can be set to any scale and it'll automatically fit.
  7. Settings for:
    1. line spacing
    2. text location within textbox
    3. textbox width, height, color, location, and gpage
    4. textbox border size and color
    5. default text speed, size, and color,
    6. functions for drawing, clipping, clearing, waiting, showing, and hiding
    7. automatic line breaks and punctuation breaks
    8. amount of time inserted automatically after each of the different punctuation marks (and even each of the different characters)
    9. the control characters
mia mia Night Person I like the quiet night and sleep late. Express Yourself Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies I think I understand most of it save for "the control characters." It seems like it has the basics included with your ... 3rd released text-box thing on PTC, but it has a lot more customization and fancy tweaks like smooth scrolling and the animated displaying and removal. Do you have an example program you used it in? Also, y'know how this allows you to control pauses as text is printed or something? I tried modifying the ... 1st text-box thing you made, but I don't think I'd saved it. I had put delays during the printing of some text or changed the pitch/sound effect maybe of others. "High pitched quick text would have a surprising feeling; low pitched slow text would have a creepy feeling." 'Sound effect.' Does your newest one play any sounds as text is printed? Either way, it sounds awesome. I'm stubborn to change and usually not motivated to download SmileBASIC Programs so it might take while, if at all, for me to move from the first text-box thing you made to the newest. -w- I wonder what you're going to use this library for. I have a guess. randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies Control characters allow you to change how the textbox operates while it's running. For instance, you can do: "This is `S2;MY`S1; house!". The `S2; and `S1; are commands which change the size of text, so after it processes `S2; the MY is now twice as big. Then we do `S1; which changes it back to the original size. There are settings in the textbox object that let you change the control characters (the ` and the ;) in case you really need to use ` in your text (; can be used without issue, but if you use ` is interprets it as a command). If you download this library, you can run TESTTB to see examples. It runs several textboxes that test various features. Yes, this one has sound effects for text output, textbox display, textbox hiding, and continue. This library is just going to be part of the game library I'm working on. Lumage Lumage Head Admin Day Person I like the warm sunshine and wake up early! Express Yourself Gardening I like to garden! Hobbies Touhou Project Is Awesome! I love Touhou Project! Express Yourself nice
randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies I added um.... a huge textbox library. If anybody actually wants to use it, let me know and I'll explain all the settings. It's nearly 100% customizable; even the functions used to render the textbox are replaceable, so there are dozens of settings. h267 h267 RNG Hidden Easter Eggs Pokemon Is Awesome! I love Pokemon! Express Yourself Good Page Hidden Achievements I would like to use it for my current new project! I was wondering if you could use them for static GUIs instead of just for things like character dialogue. But I might add a story mode where dialogue will be used. Either way, I plan on using it. randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies You could use it for a GUI. But you'd have to make all the GUI menu code yourself, so there's not much point. mezim mezim Night Person I like the quiet night and sleep late. Express Yourself Beginner Programmer I'm just starting out! I'm still trying to grasp the basics. Programming Strength Neat library =) question; is there a setting to make text boxes on the touch screen only? Nothing seemed to jump out at me, I tried using display 1 in a few different places in the library and the test code but could only get a copy on both screens at the same time randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies You should be able to just do: DIM TB$[0] TB$=TBCREATE$() DICSETI "GPAGE",1,TB$ GPAGE 1 is the touchscreen, right? However, you'll probably also have to change the widths and stuff: DICSETI "TBW",??,TB$ DICSETI "CHRW",??,TB$ DICSETI is "Dictionary Set Integer", which basically allows you to set values within the textbox. TBW is the overall width of the textbox. CHRW is the width of the character area of the textbox. Replace ?? with whatever values you'd like. Edit: You shouldn't have to change anything within the library itself. Most things things can be changed through settings using the dictionary. h267 h267 RNG Hidden Easter Eggs Pokemon Is Awesome! I love Pokemon! Express Yourself Good Page Hidden Achievements Why does this have all downvotes? Is it really that bad? Lumage Lumage Head Admin Day Person I like the warm sunshine and wake up early! Express Yourself Gardening I like to garden! Hobbies Touhou Project Is Awesome! I love Touhou Project! Express Yourself IT HAS NO DOWNVOTES Why do you do this every single time Lacks Lacks RNG Hidden Easter Eggs Day Person I like the warm sunshine and wake up early! Express Yourself Reading I like to read books! Hobbies Internet logic, point out something and some asshole will come along to ruin it. Must resist urge to hit - h267 h267 RNG Hidden Easter Eggs Pokemon Is Awesome! I love Pokemon! Express Yourself Good Page Hidden Achievements Ok sorry my browser just sucks. Delet this pleas randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies What browser doesn't support width: 100%?!? Hm maybe I should display the downvotes using the same method as the upvotes so it doesn't look like only downvotes on weird browsers. Thanks for pointing that out. Prostar Prostar Avatar Embargo I didn't change my avatar for 90 days Website Avatar Block I didn't change my avatar for 30 days. Website RNG Hidden Easter Eggs Interesting. Also, thanks for taking my image, lol. randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies YW ☆~(*^▽゜)v Lumage Lumage Head Admin Day Person I like the warm sunshine and wake up early! Express Yourself Gardening I like to garden! Hobbies Touhou Project Is Awesome! I love Touhou Project! Express Yourself You're not allowed to have triangles anymore. mia mia Night Person I like the quiet night and sleep late. Express Yourself Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Would it be helpful if I uploaded the textbox program again and shared the key with you? randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies You can if you like, but I have specific things that I want the textbox to do, so I'll probably make my own anyway. I'm sorry! mia mia Night Person I like the quiet night and sleep late. Express Yourself Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Y-you made it, th-though. randomouscrap randomouscrap Robot Hidden Easter Eggs osu! Is Awesome! I love osu! Express Yourself Drawing I like to draw! Hobbies Yeah but now I have new desires. I want the background to be transparent, and it would be nice to also be able to display textboxes on the (usually unused) graphics layer. Plus multi-textbox support and all that. mia mia Night Person I like the quiet night and sleep late. Express Yourself Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies When you said you'd make your own anyway, I thought and still think that you meant apart from the one you'd thought I'd made. The idea of making an RPG library is interesting. Good luck.