Monday, July 31, 2023

🆕 RemoveLocalStorageItem and ClearLocalStorage

(Latest version of BASIC Anywhere Machine.)

Sample program to demo all of the local storage statements and function:

LET userName$ = GetLocalStorageItem("Prog1: userName" )

LET CountProgramRuns% = VAL( GetLocalStorageItem("Prog1: runCount" ) )  + 1
SetLocalStorageItem("Prog1: runCount" , CountProgramRuns%)

IF userName$ = "" THEN
    WHILE userName$ = "" : userName$ = _PROMPT(" Enter your user name", "") : WEND
    SetLocalStorageItem("Prog1: userName" , userName$)
END IF

PRINT "Hello, " + userName$
PRINT "This program has been run " + str$(CountProgramRuns%) + " times."

SLEEP 2
IF NOT _CONFIRM("Maintain your name in local storage?") _
   THEN RemoveLocalStorageItem("Prog1: userName")
   
IF _CONFIRM("Clear local storage?") _
   THEN PRINT "PRESS A KEY TO CLEAR LOCAL STORAGE": temp$ = INPUT$(1) : ClearLocalStorage


Saturday, July 29, 2023

📚 Revisiting the "dev" and "prod" meta-programming macros

A sample program:

' This program's promotion level: <<dev """ development""">> <<prod """ production""">>

<<dev """CONST promotion_level$ = "development" """>><<prod """CONST promotion_level$ = "production" """>>

PRINT "This is the " + promotion_level$ + " version of the program."


Normally, when a program is promoted to "production", the menu items in the"development version" section of the Project Menu get disabled because the development and production versions of the code are the exact same.


As soon as we add a dev macro to a program, BAM takes into account that the development and production versions of the program, even though they may look exactly the same before pre-processing, they will be different after pre-processing.  So BAM's "development version" menu items become enabled to allow comparing the program behaviour between BAM when the dev and/or prod macro(s) is/are applied, and when the dev and/or prod macro(s) is/are not applied.

So although the exact same code for development and production...

The development Preprocess Code Viewer:

The production Preprocess Code Viewer:

We can simultaneously run both preprocessor versions of the code, and program exports can also be done for both preprocessor versions.

The sample code above is particularly useful when exporting programs and letting folk, maybe testers, know which version of the program they are inspecting (reviewing the source code, or running a program.

Documentation recap, from the dev and prod pages:

dev


Description:

The dev directive tells the BAM preprocessor to only include the contained BASIC statements IF the development version of the program is being run or exported.

This is useful when you want the program to look/behave differently depending on the promotion context.

  • Thanks to  for suggesting this kind of ability!

Syntax



prod


Description:

The prod directive tells the BAM preprocessor to only include the contained BASIC statements IF the production version of the program is being run or exported.

This is useful when you want the program to look/behave differently depending on the promotion context.

  • Thanks to  for suggesting this kind of ability!

Syntax















Friday, July 28, 2023

🆕 "enum" and "version_comment" meta-programming macros

enum


Description:

The enum macro is used to generate an enumeration of CONST statements with auto-generated and unique values starting at 1 and incremented by 1 for each constant name specified in a comma-separated list.

Syntax


  • identifier list
    • a comma-separated list of constant names
    • the list is a string that only needs to be wrapped in double-quotes if it has any spaces
  • **SPC**
    • is a space character must separate the list of identifiers from the enum keyword.

version_comment


Description:

The version_comment macro is used to generate a comment line that will be similar to:

' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2023.07.25.02.54]) on 2023.07.27 at 00:15 (Coordinated Universal Time)

The text generated by the macro comes from the "Program Version Comment" program in BASIC Anywhere Machine. View that program in BASIC Anywhere Machine (customize it to suit your needs if you like!)

Syntax



Monday, July 24, 2023

🆕 Font-Weight setting for IDE

Try out the setting in the latest version of BASIC Anywhere Machine.


Although I prefer a bold font when coding, I wanted to give folk the option of setting some other preferred font-weight.

In the Tools menu, choose the "IDE Config" menu option.  You'll find the "Font weight" setting in the top part of the editor settings.

Note that not all font-weights work with all fonts and on all web browsers.  At the very least, you should always find the Normal and Bold options work.




Saturday, July 15, 2023

🆕 "Include Libraries" section in the Code Snippets tool

To make it much easier to include libraries of code, I've added an "Include Libraries" section to the "Code Snippets" tool.

The Include Libraries section provides automatically generated include directives for all programs tagged as "library" (in a program's File Properties.)

For any library you want to include in a program, just copy and paste into your program the include directive for the related library.

For example, the following screenshot shows the "PUTSTRING" include directive in the Code Snippets" tool, and how a copy/paste of that directive in a program looks:


By the way, this is what the File Properties looks like for the "PUTSTRING(x%, y%, s$)" library program:


Not that for BAM programs and libraries, the BAM and library tags cannot be unset.  For your programs, you'll have a check box for the library tag that looks like this:





📚 About the "{{Program Version Comment}}" Pre-Processor Directive

When you place {{Program Version Comment}} in your program, this will direct the BAM Pre-Processor to replace that snippet of text with a comment with the following information:

  • The version of BASIC Anywhere Machine used to export the program
  • The date and time of program export
Here's what the directive looks like in a program, and what the results look like when viewing the Pre-Processor code:




And, here's what the code looks like when exported:




Wednesday, July 12, 2023

🆕 PCOPY Statement and ✏ _RGB, _RGB32

Added the PCOPY statement.

The PCOPY statement is used to copy an entire graphics page, or a rectangular portion of a graphics page, to another.



About graphics pages in BASIC Anywhere Machine

BAM's support for pages is currently limited.  The three pages available:
      • 0
      • 1
      • 2
Page 0 is always the active page and is always the displayed page. All screen output statements (PRINT and all graphics statements) are processed on page 0.


Modified the _RGB and _RGB32 functions


The functions  would misbehave when passed floating-point values in any of their arguments, in some circumstances requiring INT be explicitly applied to every argument.

Now, BAM implicitly (with INT) takes care of converting any floating point parameter values to integers.  So you no longer need to apply INT to your function parameters.









Friday, July 7, 2023

💡 How to (quickly) temporarily comment out large blocks of code

We can certainly comment out code with either the REM statement or a single-quote.  That gets tedious when we have many lines of code in a block we wish to comment out.

Instead, we can make use of a "pre-processor" directive (or "macro-programming") to exclude, at run-time and on export, any and all code between

  • a <!-- opening tag
  • and a --> closing tag

NOTE: BASIC comments with REM statements and single-quotes remain part of the program.  They are not excluded at either runtime (their, they are ignored) or on export.

Here's a short program with some code commented out, and the results of running that program:


Just to make the leading and trailing tags jump out more, I like to make use of some jugular-grabbing emojis.  You might find it useful to also add a little note to remind you why the code is commented out, and remind you to uncomment that code later.


Do keep in mind, though: When there are errors in a program, BAM references the line number (as in the line at which the code is located vis-à-vis the first line of the program AT RUNTIME (or upon export), as in after the code has been altered by the preprocessor.

For example, here's an error in the 6th line of the program (using the editor's line numbers), versus the line with the error at runtime:


How to find in the program what the interpreter is flagging as line 3?  Figure out what code is causing the problem by Viewing the preprocess code (Project Menu and "View Preprocess Code") for whichever version of the program you ran.


Notice that the lines of code that got commented out were replaced by a blank line.  We can see the error is a mispelled print statement, and we can use that to scan/search our program and fix the problem.


Try it out for yourself !


Another use case: to add comments to your program that will be excluded when you export the program for sharing !


Thursday, July 6, 2023

💡 Making the case for GOTO use cases

It didn't take long for me to be a "never GOTO, never ever" guy once we started to see structured BASIC implementations displace unstructured BASIC implementations.

Since I started working on BASIC Anywhere Machine back in December 2020, I've really come to appreciate the use of GOTO with line labels (instead of line numbers) in a couple of scenarios.

BASIC Anywhere Machine (aka "BAM") links:

 

Always being weary, of course, of not creating spaghetti code, here are two scenarios in which I find GOTO really practical.  When do you find GOTO useful and acceptable ?

Loops involving a lot of code

For the following blocks of code:

  • WHILE ... WEND 
  • WHILE ... LOOP
  • DO ... LOOP
  • DO WHILE ... LOOP
  • DO WHILE ... WEND
  • DO LOOP ... WHILE
  • DO LOOP ... UNTIL
If the bookends of the code block are so far apart that screen scrolling becomes necessary to see all of the code in the block, or if the code block had nested loops, matching the right bookends can become challenging.

I often prefer GOTO in these circumstances (expecially an infinite DO ... LOOP) because line labels make it easy to match the bookends of a code block.

For example:

StartLoop1: ...
...
...
GOTO StartLoop1

I find this approach concise and descriptive.


Skip over a block of code

In some circumstances, it makes more sense to me to have an IF that skips a block of code, rather than have an IF condition be satisfied to execute that block of code (and exclude the block otherwise).

Step1:
IF condition GOTO Step2
...
...
Step2:




Tuesday, July 4, 2023

📚 IF syntax documentation in progress

IF single-line conditional branch:


IF multi-statement single line


IF single-line single-statement alternatives


IF multi-line multi-alternatives code blocks


codeBlockForCondition







🆕 Tags (to describe and find programs) and ✏ New program defaults

Program Tags

Go to the File menu and click on Properties.


The "Tags" section is new.  For a selected program, click on any available check boxes to associate the program with that tag.


  Enter a new tag in the field, then press the "Create" button.  The tag will be added to the list and automatically selected.


Once any one program is tagged with some value, that tag becomes available to select for all other programs.


New feature on the "File Open" dialog: tags can be used to find programs that have all of the selected tags.


New Program Defaults now allows setting a "comprehensive" list of defaults that will be applied to new programs.


Note that this edits the program execution properties of the "New.BAS" program.  Every new program created in BAM starts off as a copy of "New.BAS".


For example, after creating a new program, here are the Program Execution Properties:



Sunday, July 2, 2023

🪲 Keyboard Input Issues Fixed

I just deployed a new version of BASIC Anywhere Machine which fixes a bad bug introduced in the previous version.  (You might need to CTRL-refresh the browser page if your browser cached the previous buggy version.)

In setting up the SLEEP statement to work with no parameter and work with a parameter of zero (both of which suspend a program until a keyboard key, or screen click/touch, is done), I went and completely broke INKEY$ and INPUT with a complete face-palm mistake.  That's going to leave a mark ...

When retronick reported the error much appreciated!), I knew right away what I messed up and where the mistake was hiding, so fifteen minutes later: voilà !

🖥 Pongy game

This program is a port (and slight mod) of the QB64pe program by SierraKen.  (SierraKen's program shared with the QB64pe community in th...