04-22-2025, 07:47 PM
(04-22-2025, 12:50 AM)James D Jarvis Wrote: Can you pass variable/arguments from one QBJS program to another using JavaScript assuming of course they are both being called from the same HTML wrapper? (not sure If I'm saying that right as my JavaScript knowledge is weak at best)There are a number of ways to do this. I think one of the simplest might be to leverage the browser's local storage. There is a simple QBJS API for getting and setting local storage values.
To demonstrate this, I put together another simple example with two programs. The first represents our very simple game which is listening for mouse clicks and then saving the score to a local storage value:
Code: (Select All)
Import Storage From "lib/web/storage.bas"
Dim score As Integer
Storage.Set "GAME_SCORE", score
Screen _NewImage(190, 120, 32)
Locate 4, 3
Print "Click here to play!"
Do
While MouseInput: Wend
If MouseButton(1) Then
score = score + 1
Storage.Set "GAME_SCORE", score
End If
Limit 10
Loop
The second program just queries the same local storage value and prints it to the screen:
Code: (Select All)
Import Storage From "lib/web/storage.bas"
Dim score As Integer
Storage.Set "GAME_SCORE", score
Screen _NewImage(190, 120, 32)
Locate 4, 3
Print "Click here to play!"
Do
While MouseInput: Wend
If MouseButton(1) Then
score = score + 1
Storage.Set "GAME_SCORE", score
End If
Limit 10
Loop
The result looks something like this:
You can try it out with the attached sample2.zip.