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

0 Members and 1 Guest are viewing this topic.

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #45 on: February 19, 2022, 11:49:46 pm »
Hey @bplus, it looks like the non-printable characters that are returned for InKey$ do not match the QB64 version at present.  I'll add that to the list.  Here is an example using the GXKeyDown function as an alternative in the meantime:

Code: QB64: [Select]
  1. _Title "15 Squares Puzzle" 'b+ mod for QBJS 2022-02-19
  2. Dim Shared As Integer board(4, 4)
  3. Dim Shared As Integer r0, c0, d
  4. Dim Shared As Integer keyState(0)
  5. Dim As Integer r, c, i, solved
  6. For r = 1 To 4
  7.     For c = 1 To 4
  8.         board(c, r) = c + (r - 1) * 4
  9.     Next
  10. board(4, 4) = 0
  11. c0 = 4
  12. r0 = 4
  13. For i = 0 To 50 * 4 * 4
  14.     d = Val(Mid$("0358", Int(Rnd * 4) + 1, 1))
  15.     handle
  16.  
  17.     Locate 1, 1
  18.     b = ""
  19.     solved = 1
  20.     For r = 1 To 4
  21.         For c = 1 To 4
  22.             If board(c, r) Then
  23.                 If board(c, r) <> c + (r - 1) * 4 Then
  24.                     solved = 0
  25.                 End If
  26.                 b = b + Right$("   " + Str$(board(c, r)), 3) + " "
  27.             Else
  28.                 b = b + "    "
  29.             End If
  30.         Next
  31.         Print b
  32.         b = ""
  33.     Next
  34.     Print
  35.     If solved Then
  36.         Locate 4 + 2, 2
  37.         Print "Solved!"
  38.         _Delay 5
  39.         'End
  40.     End If
  41.     'd = InKey$
  42.     'If Len(k) = 2 Then
  43.     '    d = (Asc(Right$(k, 1)) - 72)
  44.     '    handle
  45.     'End If
  46.     d = -1
  47.     handle
  48.     UpdateKeyState
  49.     _Limit 30
  50.  
  51. Sub handle
  52.     'Select Case d
  53.         'Case 3
  54.     If KeyPressed(GXKEY_LEFT) Or d = 3 Then
  55.             If c0 < 4 Then
  56.                 board(c0, r0) = board(c0 + 1, r0)
  57.                 board(c0 + 1, r0) = 0
  58.                 c0 = c0 + 1
  59.             End If
  60.    
  61.         'Case 5
  62.     ElseIf KeyPressed(GXKEY_RIGHT) Or d = 5 Then
  63.             If c0 > 1 Then
  64.                 board(c0, r0) = board(c0 - 1, r0)
  65.                 board(c0 - 1, r0) = 0
  66.                 c0 = c0 - 1
  67.             End If
  68.         'Case 0
  69.     ElseIf KeyPressed(GXKEY_UP) Or d = 0 Then
  70.             If r0 < 4 Then
  71.                 board(c0, r0) = board(c0, r0 + 1)
  72.                 board(c0, r0 + 1) = 0
  73.                 r0 = r0 + 1
  74.             End If
  75.         'Case 8
  76.     ElseIf KeyPressed(GXKEY_DOWN) Or d = 8 Then
  77.             If r0 > 1 Then
  78.                 board(c0, r0) = board(c0, r0 - 1)
  79.                 board(c0, r0 - 1) = 0
  80.                 r0 = r0 - 1
  81.             End If
  82.     End If
  83.     'End Select
  84.  
  85.  
  86. Function KeyPressed (key As Integer)
  87.     KeyPressed = (Not GXKeyDown(key) && keyState(key)
  88.  
  89. Sub UpdateKeyState
  90.     Dim i as integer
  91.     For i = 1 To 350 'GXKEY_UP To GXKEY_DOWN
  92.         keyState(i) = GXKeyDown(i)
  93.     Next i
  94.  

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: QBJS - QBasic for the Web
« Reply #46 on: February 20, 2022, 07:55:58 am »
https://boxgm.itch.io/qbjs

Bubble Sorting

10 ^ 3 = 0,81 s
10 ^ 4 = 78 s
10 ^ 5 = ? 780 seconds ?
10 ^ 6 = ??? 8100 seconds ??? 1,5 hours

Code: [Select]
https://v6p9d9t4.ssl.hwcdn.net/html/5279712/index.html?qbcode=BOAQAHvAM8A6QDCjgGNAMEAXlQ8JESU1gDJYBRagCmAAr4SMnqWwDTjdqCqJ/NfUd38+wklOVM0CUk5E2gFX6vuQacirCpRJh316doBq+ERQUklOVNwEFad6G9AD1zxiKiSmoqkyC8ueDppUAWo2/cwGpDz8AVtvm6AHUFJRnk+zegD55n3wzhqiQipy4AHEB0QtrmLgAW3zSWN9tYAAz/31TQ4ANASKnIjX3q6o9GTaFWjM6xNe5z637P/N19R6rDNSXtnfdy0jCWK3SVzS43A=
Code: QB64: [Select]
  1. N = 3: a = 10 ^ N: DIM d(a)
  2. FOR i = 1 TO a: d(i) = INT(RND * a): NEXT
  3. FOR i = 1 TO 5: PRINT d(i): NEXT: PRINT: z = TIMER
  4.  
  5. FOR i = 1 TO a - 1: FOR j = i + 1 TO a
  6.         IF d(i) > d(j) THEN
  7.             t = d(i)
  8.             d(i) = d(j)
  9.             d(j) = t
  10.         END IF
  11.  
  12. FOR i = 1 TO 5: PRINT d(i): NEXT: PRINT
  13. FOR i = a - 5 TO a: PRINT d(i): NEXT

error ":" without "end if"
IF d(i) > d(j) THEN t = d(i): d(i) = d(j): d(j) = t
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #47 on: February 20, 2022, 11:15:59 am »
Yeah @DANILIN, single line IF statements not working. I am surprised all your other : lines are!!!

@dbox  so are : supported?

Also can this:
Code: QB64: [Select]
  1. 'Function KeyPressed (key As Integer)
  2. '    KeyPressed = (Not GXKeyDown(key) && keyState(key)
  3. 'End Function
  4.  
  5.  
be written in such a way that QB64 doesn't red line it?

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #48 on: February 20, 2022, 01:15:38 pm »
@bplus, yes, the : line separator is supported.  The single line if/then should also work in most scenarios, I just didn’t account for the single line if/then/else.  You should also be able to use the _ to continue a line.

If you want to use the GX functions in QB64 you will need to $include the gx.bi and gx.bm files from here:

https://github.com/boxgaming/gx/tree/main/gx


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #49 on: February 20, 2022, 02:11:03 pm »
Oh look at what's at the end of 3000+ LOC GX.BM
Code: QB64: [Select]
  1.  
  2.     '$Include: 'gx_fs.bm'
  3.     '$Include: 'resource/font-default.png.bm'
  4.     '$Include: 'resource/font-default-black.png.bm'
  5.  
  6.  
  7.  

Ehh this is too much!

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #50 on: February 20, 2022, 03:03:43 pm »
Ha! Well, you did ask if it could be used in QB64.  But, yeah I get it, including the entire game engine for one method is a bit overkill.

I’ll plan to prioritize fully porting the standard QB/QB64 keyboard methods for the next build.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #51 on: February 20, 2022, 04:33:57 pm »
@dbox

I'm sorry, bad day, too crabby! What you are working on is really good! Ground level stuff requires patience.

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #52 on: February 21, 2022, 12:08:37 am »
Bubble Sorting

10 ^ 3 = 0,81 s
10 ^ 4 = 78 s
10 ^ 5 = ? 780 seconds ?
10 ^ 6 = ??? 8100 seconds ??? 1,5 hours

Hey @DANILIN this is a good example for testing out performance improvements.  I'll look into this one further.  There is definitely a significant difference between the QBJS version and the natively complied version.

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: QBJS - QBasic for the Web
« Reply #53 on: February 21, 2022, 01:05:57 am »
2d arrays matrix are supported?

simply in "Bubble Sorting" replace "d(" on "d(5, "

Javascript without variables:
 
var d = QB.initArray([ 5], }); //


update:
Code: QB64: [Select]
  1. Dim As Integer matrix(5, 5)
  2. matrix(1, 1) = 3: matrix(2, 2) = 5: matrix(3, 3) = 7
  3.      
  4. for i = 1 to 5: for j = 1 to 5
  5.     Print matrix(i, j);

30000
05000
00700
00000
00000
« Last Edit: February 21, 2022, 09:07:10 am by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #54 on: February 21, 2022, 08:13:32 am »
Hi @DANILIN.  Looks like you found an issue with the Dim/Redim that I need to fix.  There is an issue when you declare a multi-dimensional array like this:
Code: QB64: [Select]
  1. Dim matrix(5, 5) As Integer
  2.  

I will add this to the list for the next build.   In the meantime, if you declare the array with the newer Dim As Type syntax it will work as expected:

Code: QB64: [Select]
  1. Dim As Integer matrix(5, 5)
  2.  
  3. matrix(1, 1) = 3
  4. matrix(1, 2) = 5
  5. matrix(3, 4) = 7
  6.  
  7. Print matrix(1, 1)
  8. Print matrix(1, 2)
  9. Print matrix(3, 4)
  10. Print matrix(5, 5)
  11.  

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #55 on: February 21, 2022, 11:06:05 am »
Fun fact: you can include native javascript in your QBJS program.  This is to allow you to use external libraries or generally just add additional functionality.  This would be analogous to calling out to a DLL in QB64 or calling inline assembly in classic QBasic.

Here's a simple example that will create a message box method by calling out to javascript's alert function:
Code: QB64: [Select]
  1. Input "Enter the message text: ", msg
  2.  
  3. MessageBox msg
  4.  
  5. Print "After message"
  6.  
  7. Sub MessageBox (text As String)
  8. $If Javascript
  9.     alert(text);
  10. $End If  
  11.  

View in QBJS
« Last Edit: March 15, 2022, 06:48:57 pm by dbox »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #56 on: February 21, 2022, 11:47:28 am »
@dbox

We (I) need a public check list of known issues unsupported or differences with QB64, that is detailed enough to pin point problem so that we (I) don't go trying to fix things not broken or attempt things not possible because of an issue like anything using arrow keys and probably all len(2) INKEY$ returns.

The : thing, works unless in one-liner If.
The keys number thing, work unless beyond the ascii list.
Something about dimensioning strings?
DIM a$, b$, c$ ' does not work (or did not for me once with 15 squares puzzle)
DIM as string a, b, c ' does work

DIM as something a, b, c works better than DIM a as something, b as something,...

2 Dimensional arrays work but assume base 1?

These are what I vaguely have picked up along the way in this thread but I am sure I don't have things clearly correct.

Perhaps we can track these issues in updated Supported Keywords page I am constantly consulting:
https://github.com/boxgaming/qbjs/wiki/Supported-Keywords

Like a pilot for an aircraft, a QB64 coder has a list of items to check before take off.

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #57 on: February 21, 2022, 12:16:46 pm »
Hey @bplus.  That was the intent of this page that I referenced in the first post:

QBasic Language Support

However, there are several things that have been discovered since I posted that need to be added to this page.  Perhaps to make it easier to reference I can put a bulleted list at the top, similar to what you've created here with links to the detail to make it easier to scan through.  I'll also update the keyword reference page for the issues that have been discovered that are related to a specific keyword.


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #58 on: February 21, 2022, 01:08:57 pm »
Hey @bplus.  That was the intent of this page that I referenced in the first post:

QBasic Language Support

However, there are several things that have been discovered since I posted that need to be added to this page.  Perhaps to make it easier to reference I can put a bulleted list at the top, similar to what you've created here with links to the detail to make it easier to scan through.  I'll also update the keyword reference page for the issues that have been discovered that are related to a specific keyword.

That would be great. See, I am making a sort of mental checklist but never sure it is correct in detail and extent.

It also may be good for a Punch list for you.

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #59 on: February 21, 2022, 06:48:35 pm »
Hey @bplus, I found a temporary workaround for the delay and KeyClear issue until I can get a new build out.  This seems to be working as intended now:

View Hangman in QBJS
« Last Edit: March 15, 2022, 06:49:35 pm by dbox »