Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
N7 version 24.01.23 released
#1
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"
Reply


Messages In This Thread
N7 version 24.01.23 released - by Marcus - 01-23-2024, 06:00 PM
RE: N7 version 24.01.23 released - by Marcus - 01-23-2024, 06:05 PM
RE: N7 version 24.01.23 released - by 1micha.elok - 01-24-2024, 02:22 AM
RE: N7 version 24.01.23 released - by johnno56 - 01-24-2024, 05:00 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)