NaaLaa

Full Version: N7 version 24.01.23 released
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Sorry about posting another update so shortly after the last one, but it's an important update ... for myself.

https://naalaa.com/n7/N7_240123.zip

2024-01-23
  • Added the 'download' function
  • Added the game Denaalaafender to examples/other

I want to write a library for online leaderboards (there was such a library for N6, but I'm not sure if it's still working), so I really need the 'download' function, which you can use to retrieve data from php scripts and such.

This is the download.n7 example from the examples/help folder. It downloads the n7 changelog in three different ways.

Code:
' download.n7
' -----------

' You can use 'download(url, filename)' to download something from the internet to a destination
' file. The function returns true on success or false on failure. Depending on where you've put
' your N7 directory, this example might fail.
if download("https://naalaa.com/n7/CHANGELOG.txt", "my_file.txt")
    pln "Downloaded to file successfully!"
    pln
else
    pln "Download to file failed!"
    pln
endif
wait 1000

' If you know that the url will produce pure text, you can use 'download(url, TYPE_STRING)' to
' get the result as a string. If the download fails, an unset variable is returned.
aString = download("https://naalaa.com/n7/CHANGELOG.txt", TYPE_STRING)
if typeof(aString) ' TYPE_UNSET is 0, so we can just write this instead of 'if typeof(aString) = TYPE_STRING'
    pln "Downloaded to string successfully!"
    pln
    wait 1000
    ' Print the string.
    pln aString
    pln
else
    pln "Download to string failed!"
endif
wait 1000

' If you, for some reason, want the downloaded data as an array of bytes, you can use 'download(url,
' TYPE_TABLE)'. If the download fails, an unset variable is returned.
anArray = download("https://naalaa.com/n7/CHANGELOG.txt", TYPE_TABLE)
if typeof(anArray)
    pln "Downloaded to byte array successfully!"
    pln
    wait 1000
    ' Just print the first line of text (we know it's text this time)
    i = 0
    ' Use 'chr' to convert the ASCII values (bytes) to characters.
    while anArray[i] <> 10
        write chr(anArray[i])
        i = i + 1
    wend
    pln
else
    pln "Download to byte array failed!"
endif
pln

system "pause"
Actually it would have been possible to download files in earlier n7 versions using the 'system' function and curl (which is shipped with windows since Windows 10), but I prefer not having to depend on external programs for these things.
(01-23-2024, 06:00 PM)Marcus Wrote: [ -> ]Sorry about posting another update so shortly after the last one, but it's an important update ...

There are many new posts in Naalaa forum since last week, it's very productive and very good...Thumb Up  Big Grin
The Naalaa's forum is ALIVE  Cool
"Sorry about posting another update so shortly after the last one, but it's an important update ... for myself."

Better late than never... Cool...

J