Author Topic: QBJS - QBasic for the Web  (Read 11676 times)

0 Members and 1 Guest are viewing this topic.

Offline dbox

  • Newbie
  • Posts: 80
QBJS - QBasic for the Web
« on: February 18, 2022, 09:58:59 am »
Update 30-Mar-2022
New beta release v0.3.0
https://qb64forum.alephc.xyz/index.php?topic=4670.msg141653#msg141653



Hi All,

I've decided to spin off QBJS into it's own project.  This started as a feature of the GX game engine https://qb64forum.alephc.xyz/index.php?topic=4481.0 that allows you to publish games built in QB64 for the web.  Based on the interest in this feature I've created a new stand-alone project: QBJS.

 
qbjs-screenshot.png


The goal here is to recreate the feel and accessibility of programming in QBasic/QB64 in the browser.  You can try it out here:

https://boxgm.itch.io/qbjs

This is still a work-in-progress, but it is pretty functional at this point so I thought I would share with a wider audience to get some additional feedback.  I've tried to document what is currently supported here:
https://github.com/boxgaming/qbjs/wiki/QBasic-Language-Support
https://github.com/boxgaming/qbjs/wiki/Supported-Keywords

« Last Edit: March 30, 2022, 11:59:50 pm by dbox »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: QBJS - QBasic for the Web
« Reply #1 on: February 18, 2022, 10:33:13 am »
Wow that's interesting!

Offline dbox

  • Newbie
  • Posts: 80
Re: QBJS - QBasic for the Web
« Reply #2 on: February 18, 2022, 11:47:23 am »
Hey @bplus, if you get a cool example working there use the share link and post it back here and we can add it to the samples list.

Here's an example that should look familiar:
Quick Falling Letters Game
« Last Edit: March 15, 2022, 06:50:59 pm by dbox »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: QBJS - QBasic for the Web
« Reply #3 on: February 18, 2022, 12:45:58 pm »
Hey yeah! I will set up a folder and check out list of Keywords you have working...

I sure like doing Quick demos. I just finished a trans of Animal to JB, using a file to save learning questions and answers.

How would Loading and Saving files work with this system? Normal? TBA?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: QBJS - QBasic for the Web
« Reply #4 on: February 18, 2022, 12:58:29 pm »
Oh, just tried Falling Letters and wondered why it wasn't working, seems part of the right side was missing from my view of screen. What are the output screen dimensions?

PS I see we don't do files yet.

Offline dbox

  • Newbie
  • Posts: 80
Re: QBJS - QBasic for the Web
« Reply #5 on: February 18, 2022, 01:09:06 pm »
The editor defaults to 600px wide.  You can change the view to view just the output panel or just the code editor with the small left and right buttons in the area between the panels.

The output screen dimensions are based on the screen command. If this is omitted then it defaults to screen 0 size (640x400).

Perhaps for a future update I will make this default to a certain percentage of the screen rather than a fixed size.

Offline dbox

  • Newbie
  • Posts: 80
Re: QBJS - QBasic for the Web
« Reply #6 on: February 18, 2022, 01:22:14 pm »
PS I see we don't do files yet.

File I/O is definitely still a work-in-progress.  I do plan to support the OPEN/INPUT mechanism for reading external file content.  Writing files in the web context is more complex due to web security rules.  Just in general accessing the local machine is a no-no, but there are options to explore for utilizing local browser storage or cloud-hosted storage.

There is currently a QBJS-specific keyword for reading file content from a provided URL.  This is still a bit experimental so I haven't added it to the documentation.  Here is an example of reading content directly from an online location (this one specifically reads from the qbjs github):
Code: QB64: [Select]
  1. Screen _NewImage(800, 600, 32)
  2.  
  3. Dim res as FetchResponse
  4. res = Fetch("https://raw.githubusercontent.com/boxgaming/gx/main/LICENSE")
  5. Print "OK: "; res.ok
  6. Print "Status: "; res.status
  7. Print "Status Text: "; res.statusText
  8. Print "Response Text"
  9. Print "-------------------------------------"
  10. Print res.text
  11.  

Offline Dav

  • Forum Resident
  • Posts: 792
Re: QBJS - QBasic for the Web
« Reply #7 on: February 18, 2022, 01:34:27 pm »
This is cool! Looks like you’ve done a great job.  I’m going to play with it some more later today.

- Dav

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Re: QBJS - QBasic for the Web
« Reply #8 on: February 18, 2022, 01:58:13 pm »
PS I see we don't do files yet.

Do you mean an Open/Save dialog for your programs saved on your local hard drive or OPEN "file.txt" FOR BINARY etc?  For the former, I just use notepad plus copy/paste as quick and easy intermediate. 

Ultimately, you can probably do something with the QB64 IDE or any other editor and have a script generate a base64 URL, open a browser and instant run when you press F5.  But yeah, it can't lock you into a comfortable playpen like JB but then again there's a whole universe waiting outside!

Offline dbox

  • Newbie
  • Posts: 80
Re: QBJS - QBasic for the Web
« Reply #9 on: February 18, 2022, 02:30:50 pm »
This is cool! Looks like you’ve done a great job.  I’m going to play with it some more later today.

- Dav

Thanks @Dav, I'd be curious in any feedback you have.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: QBJS - QBasic for the Web
« Reply #10 on: February 18, 2022, 03:21:02 pm »
the idea is very big! It gives a huge space to any QB program. An idea, an implementation, would be easier to reach people who didn’t even know what “QB” was. I wish you much success on your journey!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: QBJS - QBasic for the Web
« Reply #11 on: February 18, 2022, 04:57:17 pm »
Do you mean an Open/Save dialog for your programs saved on your local hard drive or OPEN "file.txt" FOR BINARY etc?  For the former, I just use notepad plus copy/paste as quick and easy intermediate. 

Ultimately, you can probably do something with the QB64 IDE or any other editor and have a script generate a base64 URL, open a browser and instant run when you press F5.  But yeah, it can't lock you into a comfortable playpen like JB but then again there's a whole universe waiting outside!

Hi @_vince  I meant using a file for adding data and saving. I am still fresh from Animal Guessing translation to JB and very impressed how this old code holds up so well over time like Eliza. Seems pretty smart for about 100 LOC.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: QBJS - QBasic for the Web
« Reply #12 on: February 18, 2022, 05:57:01 pm »
I think this is pretty cool... QB via a web page... Impressive.

dbox. I think what you have done so far is brilliant! Looking forward to future updates!

Potential 'can of worms' scenario... Adding save'load would be a nice idea... but for people like myself. who are inherently lazy, would use QB.JS because I would not have to install QB... If the goal is to 'replace' QB4.5 then adding file function would be ideal. But, having QB64 functions within QB.JS, in my opinion, may convince some not to install QB64...  Am I over analysing this?

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: QBJS - QBasic for the Web
« Reply #13 on: February 18, 2022, 06:59:46 pm »
https://v6p9d9t4.ssl.hwcdn.net/html/5279712/index.html?qbcode=FEbwBQBBUK5srG5MrpQD2BJLc6MAoQSk3MigFSAGPgGHPAFLACt3wdkPMRJbnB1dLQCJwiO6srm51gtrzYK3OraxMrlQVYLo3zEVndQDtIRndWVzc4D3wUlmvb6d4NUaGVurhorw0ulgf7e7aAPL61sCKDk0tzpGiC2N4y/2aKgB9XrVNJ4LQ0uLwQ0xvb3CYIqtzo0tlFeIvOvdhLLe6xAmdvdLUFpdHwBCBe2guJquVOw=

Share link?

Here is code for simple "Hello World!" Game I try on new things.
Code: QB64: [Select]
  1.     secret = Int(Rnd * 100) + 1
  2.     Do
  3.         Input "Guess my number (1 to 100) "; guess
  4.         If guess = 0 Then Exit Do
  5.         If guess < secret Then Print "lo"
  6.         If guess > secret Then Print "hi"
  7.     Loop Until guess = secret
  8.     Print "You got it!"
  9.     Print
  10. Loop Until guess = 0
  11.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: QBJS - QBasic for the Web
« Reply #14 on: February 18, 2022, 07:15:31 pm »
Hmm.... no Sub or Function, no GoTo nor GoSub? They are not in Supported Keywords but I see Sub and Function in samples. Also Shared but in Vector Field Code like Sub and Function.

Is DIM required of everything? No, I didn't in above code.
« Last Edit: February 18, 2022, 07:29:42 pm by bplus »