Share My Creation B4Script - On device basic programming

I am pleased to announce B4Script, an enhanced version of B4A master user AGraham's BasicIDE app. Several things have been modified, moved, added or improved.

The core of both BasicIDE and B4Script is the BasicLibIDE script execution library, by AGraham, which has not changed. Only the IDE and Android extensions have been modified. All credit and gratitude for the library belongs to AGraham.

Changes. To start with the menu structure is completely changed. Gone are the buttons, checkboxes and labels under the editor window. Those have been moved to the Debug menu option. All file operations, including project operations, are in the File Menu option. There is also a Settings menu option. Adding and removing line numbers have also been moved to the Debug menu. This is because the editor edittext view now takes up the entire space of the screen, and automatically resizes when the soft keyboard pops up. This is the way it is supposed to be. It feels right now. Thank you Erel.

One thing to note: Some of the menu options and selection lists use InputList, which I don't like much because the appear cheesy, for the sake of reduced development time, and will be replaced with nicer, more functional prompts and dialogs at some point in the future. The help files for now are the standard BasicIDE help files, and will also be reformatted to appear more pleasing at some point in the future.

The file structure has changed. No longer are files stored in the B4Script folder. There is now the concept of projects. A project is a group of files, some are B4Script files, some are other files like text files and bitmaps, that are stored in their own folder in the B4Script/Projects folder. In IDE mode, FileDirAssets points to this folder. In APK mode, which will be introduced at some point to allow compilation of B4Script projects into an actual APK file that can be uploaded to the Android Market, FileDirAssets points to the actual assets folder. It should also be noted, because I forgot to update the help screens, that FileDirInternal and FileDirDefaultExternal, in IDE mode will point to the projects dir in B4Scripts internal and default external dir's. In APK mode, these dir pathnames will correctly point to the dir as specified by their respective package names, and will not be related to B4Script.

Scripts within a project can run each other with the new Chain and Run commands. In this light, each script is an activity that can be started and stopped at will.

As mentioned in the readme file, standalone scripts, ie. those not associated with a project, are stored in the B4Script/Scripts folder. These are listed in the File/Load menu option when a project is not open. To access one of these when a project is open, first close the project, the use the File/Load menu option.

Creating a new project creates the new folder with the new project name, opens the project, and also creates a new B4Script file by the same name in that folder.

Opening an existing project will limit loading and saving scripts to that project. Close the project to access standalone scripts, or scripts in other projects. Place bitmaps and other files in the project folder with the scripts to access them from the project scripts via the FileDirAssets dir.

My apologies for the lack of time to present this project properly. The help files have been updated. Of importance, is to explore it and have fun.

Change Log:
------------
1.0b: 02/28/12 - Initial beta release
1.00b: 02/28/12 - See post 4 for details
1.01b: skipped somehow >blush<
1.02: 04/10/12 - See post 8 for details
1.03.01: 04/29/12 - See this post for details
1.04: 05/14/12 - see this post for details
1.05: 05-22/12 - see this post for details. See this post for a custom menu system

From this point forward, download the completed app file here.

1.07: 11/13/12 - see this post this post for details.
01/08/13 - uploaded Basic4android project so B4Script projects can be compiled directly to a publishable app. See link above.

To Do List:
-----------
Create a scripts 'gallery' as the startup page for single click running and editing of scripts
Tidy up B4A code
*DONE!* Create APK version of project for simple APK compilation
Create nicer prompts and secondary menus
Create new context sensative help system with updated polished content
Make all B4A view events available
Make all B4A constants available (like Gravity_Top, etc...)
*DONE: #INCLUDE directive to include other scripts at runtime
Autoload settings option to automatically reload last edited script at startup
#AUTOLOAD directive to save cursor position and set it back up when script is loaded
#DEBUG directive to save and load the current scripts debug when script is loaded
Create a list of Sub's for quick and easy code access
Code segregation to isolate one sub at a time in the editor window. Will work with Sub list.
Find and replace in the editor
Try to find a way to read and convert B4A's layout files, so your script's screens can be designed in the B4A designer. I'm thinking if I can read them I can create a B4Script layout file which would be no more than a series of addview, setcolor, settextcolor, etc... statements compiled into a single file, then #INCLUDEd into the project's scripts. Gonna need some help with this Erel :)
Setting option for editor edittext background color

Want something added to the To Do List? Just ask :D
 
Last edited:

JesseW

Active Member
Licensed User
Longtime User
Andrew, I just noticed the chain/run statements do not call activity_pause before loading the new script. since I had originally envisioned each script of a project being its own activity, I am now thinking activity_pause should be called.

do you have comments either way?
 

JesseW

Active Member
Licensed User
Longtime User
blib_ended no longer calls activity.finish when chaining. it simply sets a 10ms timer so blib_ended can exit, then the timer restarts blib with the new script. activity_resume is manually called when blib_ended is called at the end of the main code segment. this is a much quicker and elegant solution than switching activities and the only negative is the menu items don't reset, but I am writing a custom menu for that.

I was really hoping you knew of a hook in android that would allow for a manual activity restart that you'd show me how to activate with reflection. :) (hey, a guy can hope, can't he?)
 

JesseW

Active Member
Licensed User
Longtime User
Version 1.05 is here! This is a major update. Lots of things have been added and updated. Here's the list:

- Added HideKeyboard command
- Open Project menu option now displays a list of files to load instead of automatically loading the projects main script
- Find & Replace is now working. It's a bit clunky, but it works nicely.
- The Help menu option has been replaced by Misc. Help is now an option inside Misc
- Undo has been added. It allows a single level undo for now. A later release may provide multiple levels
- A new directive, #STACKSIZE has been added. The stacksize may be set in settings, but each programs memory requirements are different, so if this new directive is in a script, it will be used instead of the value in settings. To use, enter #STACKSIZE 16 on a line by itself (replace 16 with the value you want)
- A new menu option, Copy To, has been added in the File menu. Once a script is in the editor, use Copy To to copy it to another project. This is useful if you have a project called Includes which has all your include files. They may now easily be copied right from B4Script
- Saving a script now creates automatic backups. It can be turned off in settings, but should be left on unless storage is critically low. Currently, it has a bug and saves two copies of the file instead of just one, and I can't find it. Help???
- Fixed a bug or two in the Gravity_ constants
- Improved logic of the #INCLUDE directive to not include the same script twice
- Improved logic of the #INCLUDE directive to merge sub's. How this works: The main code section (before the first Sub statement) of the included script replaces the #INCLUDE directive of the including script. The each sub in the included script is examined and if it exists already in the including script, the code body of the included script is placed at the top of the matching sub in the including script, just below the Sub statement. This allows for additional functionality to be added to an already existing code sub. If there is no matching sub in the including script, the included sub is added to the end of the including script. In the next post, I will upload and explain a custom menu system written entirely in B4Script, which uses this conecpt.
- Scripts included with the #INCLUDE directive are now marked with ###Begin and ###End tags in the final script. To demonstrate, write one script to include another, then use the File / Merge Scripts option to display the merged, or final, script.
- If a script uses the Chain, Run or Restart statements, AND the script has finished the main code block and the Activity_Resume event sub has finished executing, the Activity_Pause event sub will now be executed before the script chains to the next script. Note that if the Chain, Run or Restart statements are called from the main code section or the Activity_Resume sub, Acitivity_Pause will not be called. *** Andrew, is this the correct way of doing this?
- You are now warned of an overwrite while saving a script

I had coded the AddDefaultEdittext statement, but the edittext fields it created were not correct, so the code is still there, but remarked out, and the statement was removed from the Blib.AddSysCalls method. If anyone has a desperate use for it, let me know.

See the first post for the download link...

Most importantly... Enjoy!!!
 
Last edited:

JesseW

Active Member
Licensed User
Longtime User
Here is the Custom Menu include file. In the zip is a readme which explains how to use it. The script is documented for your learning pleasure :) About the only differences are there are three rows of 4 items max, for a possible 12 items, instead of just 6, and there is no raising up animation.

The reason for the custom menu is there is currently no way in Basic4Android to remove items from the system menu. In B4Script, it is now possible to have a project with many scripts which call each other using Chain and Run statements. It is possible that each of these scripts will have different needs that require different menu items. Without restarting the underlying activity, there's no way to replace menu items. So a custom menu system was designed to overcome this limitation. Each script can now have its own independent menu items, easily accessed from the script.

Remember, this menu system is written completely in B4Script. There's not much this little powerhouse development system can't do.

Hope you enjoy...
 

Attachments

  • custommenu.zip
    3.1 KB · Views: 539
Last edited:

ScriptBasic

Member
Licensed User
Longtime User
I'm running on a Samsung Galaxy Tab 2 10.1 tablet and there seems to be a difference in the UI theme between BasicIDE and Basic4Android apps. The buttons in BasicIDE seem flat where B4A buttons have a theme to them. It may just be me as the scale factoring to fit on on my tablet may be distorting the controls.

:sign0104:
 
Last edited:

ScriptBasic

Member
Licensed User
Longtime User
Can I (re)compile BasicIDE with the DBUtils library for SQLite3 support? Is this what CallHostSub is used for?
 

agraham

Expert
Licensed User
Longtime User
"CallHostSub" (which also has the alias "Sys") was the original way to extend the capabilities of a script by accessing Basic4android Subs. The latest version of BasicLibIDE supports adding your own keywords by "AddSysCalls" which uses the same calling mechanism as "CallHostSub" but makes your added functions look as though they are part of the script language. The BasicIDE demo uses this to implement the graphical capabilities. Look at the "Custom Functions" region at line 1995 in the Script module of the demo.
 

ScriptBasic

Member
Licensed User
Longtime User
That is a great feature to help expand on the interpreter / GUI designer.

Is the Script.bas file the only place one needs to reference the new function in the language?

I'm going to try and add DBUtils to the language and see how far I get. :sign0095:
 

agraham

Expert
Licensed User
Longtime User
Is the Script.bas file the only place one needs to reference the new function in the language?
I don't inderstand what you mean by "reference" in this context. However the new functions are called using the Basic4android event mechanism in the same way that the other BasicLib Events like Loaded and Starting are called. This means that the called function must reside in the activity in which the BasicLibIDE object is Initialized. They in turn can of course then call Subs declared in a code module if you want to move clutter out of the activity.
 
Last edited:

JesseW

Active Member
Licensed User
Longtime User
A new version of B4Script has been posted. The download method has been changed from downloading a Basic4Android project file and compiling it to downloading a complete app file. The .apk app file may be found here

Its been a while since I've uploaded a new version, and there are many enhancements, unfortunately too many to remember :( Among the important ones: a new help file display format for the Android Extensions Help option. Also, B4Script is now using the new version of the BasicLibIde library that pulls all the roots out of the script.bas file and allows for complete control of the functions outside the core language.

I've experienced some issues with the Static and AppStatic statements when using more than a few arrays, and I've not had time to resolve them.

Jesse
 

JesseW

Active Member
Licensed User
Longtime User
MMaze - Mage generator and explorer

This is a little something I did in my spare time. It started out as a simple maze generator, just to see if I could still remember how to do it from the old 8-bit days. After that was finished, I was able to flush in some code to display the maze in 3D. This script demonstrates graphics rendering for both the B4Script and BasicLibIde apps.

While you are navigating through the maze, remember the north star is visible in the northern sky and the moon in the southern sky.

It's not completely finished, as you'll see when you step on the red exit square (it doesn't end the game), so you'll have a little challenge yourself, but for the most part, the generation, rendering and navigation routines are all complete and working.

To start, choose a skill level by selecting the size of the maze. After it have been generated, touch the [Continue] button, then navigate through the 3D maze to your thumbs delight. Hope you enjoy.

Note: although it was developed for the B4Script app, it should work with little modification with AGraham's BasicLibIde app. I haven't tested it, but I do know you'll have to add at least this function to the mmaze.b4s file, then rename it to mmaze.src:

B4X:
Sub IIf(expr, trueval, falseval)
  If expr Then
    Return trueval
  Else
    Return falseval
  Endif
End Sub

If it proves too difficult to convert to BasicLibIde, please download the B4script app from here.

I do not mind if you borrow some of this code for your own projects. Please feel free...
 

Attachments

  • mmaze.zip
    3.2 KB · Views: 581
  • Screenshot_2012-11-13-11-26-09.png
    Screenshot_2012-11-13-11-26-09.png
    58.3 KB · Views: 604
  • Screenshot_2012-11-13-11-26-22.png
    Screenshot_2012-11-13-11-26-22.png
    20.9 KB · Views: 624
  • Screenshot_2012-11-13-11-26-32.png
    Screenshot_2012-11-13-11-26-32.png
    18.5 KB · Views: 588
  • Screenshot_2012-11-13-12-18-10[1].png
    Screenshot_2012-11-13-12-18-10[1].png
    20.8 KB · Views: 576
Last edited:

nypaulie

Active Member
Licensed User
Longtime User
Creating an apk file.

Thanks JesseW! I've been playing with the demo B4Script you've linked and have made some of my own .b4s files. I want to know if it's possible to make apk files from these (.b4s files) or is this something you are working on.
 

JesseW

Active Member
Licensed User
Longtime User
Thanks JesseW! I've been playing with the demo B4Script you've linked and have made some of my own .b4s files. I want to know if it's possible to make apk files from these (.b4s files) or is this something you are working on.

Edit: Paulie, I'd sent you a private message. You may disregard that message. I've published the project as described below. Have fun!
 
Last edited:

JesseW

Active Member
Licensed User
Longtime User
I've posted the project for Basic4android that allows B4Script projects to be compiled as .apk apps here.
 

JesseW

Active Member
Licensed User
Longtime User
Version 1.11 is now online here. It adds the ability to add shortcuts to your homescreen, that launch project scripts when touched.

I've been wanting to add this for a LONG TIME. Im so glad it's here! :sign0060:
 

JesseW

Active Member
Licensed User
Longtime User
Andrew, I plan to add the remaining views methods and events. there'llbe quite a few. do you forsee any pperformance degradation? thx
 
Top