04-27-2023, 03:17 AM
(04-21-2023, 08:11 PM)dbox Wrote: Have you ever wished you had a desktop background that would tell you random Chuck Norris facts? Haven't we all?
Well now your wish has become a reality:
Code: (Select All)Dim img
img = _LoadImage("https://images01.military.com/sites/default/files/styles/full/public/2021-04/chucknorris.jpeg.jpg?itok=2b4A6n29")
_PutImage , img
_Fullscreen
Do
_Delay 2
Dim result As Object
result = Fetch("https://api.chucknorris.io/jokes/random")
If result.ok Then
Dim obj As Object
obj = JSON.parse(result.text)
Say obj.value
End If
Loop
Sub Say (text As String)
$If Javascript Then
var synth = window.speechSynthesis;
if (synth) {
var utterance = new SpeechSynthesisUtterance(text);
synth.speak(utterance);
while (synth.speaking) {
await QB.sub__Delay(.5);
}
success = -1;
}
$End If
End Sub
View in QBJS
This is really great. Questions:
1. Everything is JS in QBJS - except how you write it using QB syntax or not, still transpiles to JS, right?
2. Fetch! That's awesome, does this have a QB64 counterpart?
3. JSON.parse - native JS inside the QBJS part - it's a little confusing to me - this is javascript inside of QBJS but without $If Javascript like lower down - can you explain how you do that, or how we would know what we can do? If it's in the docs, I'm sorry.
Thanks for sharing this great and simple example.