Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 37
» Latest member: Ludwig
» Forum threads: 211
» Forum posts: 1,585

Full Statistics

Online Users
There are currently 123 online users.
» 0 Member(s) | 122 Guest(s)
Bing

Latest Threads
NaaLaa VS RCBasic
Forum: Programming
Last Post: Marcus
2 hours ago
» Replies: 4
» Views: 42
NaaLaa VS SmallBASIC
Forum: Everything else
Last Post: johnno56
Yesterday, 09:21 PM
» Replies: 4
» Views: 96
A BASIC facebook group wi...
Forum: Programming
Last Post: aurel
Yesterday, 09:16 PM
» Replies: 10
» Views: 284
Raylib and SmallBASIC....
Forum: Programming
Last Post: luwal
Yesterday, 01:09 AM
» Replies: 8
» Views: 329
The most used BASIC diale...
Forum: Programming
Last Post: luwal
05-13-2025, 09:02 AM
» Replies: 14
» Views: 902
Turbo Rascal Syntax Error...
Forum: Programming
Last Post: luwal
05-13-2025, 01:50 AM
» Replies: 2
» Views: 82
Any plan to change the th...
Forum: Suggestions
Last Post: luwal
05-13-2025, 01:37 AM
» Replies: 0
» Views: 30
Malay Basic ?
Forum: Everything else
Last Post: luwal
05-13-2025, 01:16 AM
» Replies: 2
» Views: 63
Typing Trainer (repost)
Forum: NaaLaa 7 Code
Last Post: johnno56
05-08-2025, 12:29 PM
» Replies: 4
» Views: 265
Craft Basic,Express BASIC...
Forum: Programming
Last Post: luwal
05-07-2025, 02:07 AM
» Replies: 0
» Views: 91

 
  Example of using tables
Posted by: Tomaaz - 02-09-2024, 01:47 PM - Forum: NaaLaa 7 Code - Replies (9)

Again, it's not the type of program NaaLaa has been designed for, but it's one from my long list of simple programs I test every single language I try with. Some the members here may remember the word count challenge we had on basicprogramming.org. N6 was pretty useless at this task, but N7 is a completely different beast. I was impressed by how easy (thanx to tables, the split function and the free val procedure) was to write this program, considering the fact that NaaLaa doesn't have sorting algorithms built-in.

The task is to read a text file, remove all non-word characters, count all words, count unique words, count how many times each word appears in the text, sort the words by occurrence an save the result to the file.  And here is the code:

Code:
open file 1, "Hamlet.txt"

whole_text = ""
x = freadc(1)
while x
    if x < 48 or (x > 57 and x < 65) or (x > 90 and x < 97) or x > 122
        whole_text = whole_text + chr(32)
    elseif x > 64 and x < 91 then
        whole_text = whole_text + chr(x + 32)
    else
        whole_text = whole_text + chr(x)
    endif
    x = freadc(1)
wend

all_words = split(whole_text, " ")

words_number = 0
unique_words = []
foreach n in all_words
    if len(n) > 1 or n = "a" or n ="i"
        unique_words[n] = unique_words[n] + 1
        words_number = words_number + 1
    endif
next

create file 2, "Words.txt"
wln file 2, "All words - " + words_number
wln file 2, "Unique words - " + sizeof(unique_words)
wln file 2, ""

y = 1
while sizeof(unique_words)
    foreach a, b in unique_words
        if b = y then
            wln file 2, a + " - " + b
        endif
    next    
    free val unique_words, y
    y = y + 1
wend

OK. And now let's move to graphics and games. I won't bore you with this kind of programs, anymore. Wink



Attached Files
.zip   words.zip (Size: 72.74 KB / Downloads: 8)
Print this item

  Calculating 10000 digits of Pi
Posted by: Tomaaz - 02-07-2024, 06:07 PM - Forum: NaaLaa 7 Code - Replies (3)

OK. I know this is not the kind of program NaaLaa has been created for, but I use it to test the speed of any language I try. Well, NaaLaa is doing a pretty good job here and runing this example as fast as other fast interpreters. Smile 

Code:
n = 35001
a = 10000
d = 0
k = 0
g = 0
l = 0
f = []

for x = 0 to n
    f[x] = 2000
next

for c = n to 14 step -14
        d = 0
        for b = c to 1 step -1
            d = d * b
            g = b * 2 - 1
            d = d + f[b] * a
            f[b] = d % g
            d = floor(d / g)
            k = l + floor(d / a)
        next
        k2 = right("0000" + k, 4)
        write k
        l = d % a
next

EDIT: On my machine it takes about 1 min. to complete the task and this is the speed I'm expecting from an interpreted language. Python is slightly faster, while Perl being 25% faster than Python. Tcl is 10+ times slower than NaaLaa. It's worth to remember that NaaLaa runs through Wine, while Python, Perl and Tcl run natively.

Print this item

  Draw pixel and alpha channel
Posted by: Tomaaz - 02-07-2024, 05:50 PM - Forum: NaaLaa 7 Questions - Replies (13)

Here is the Bubble Universe example. It seems that alpha element doesn't affect drawing single pixels:

Code:
set window "Bubble Universe", 512, 512
r = 6.283185307179586 / 235
mw = 512
mh = 512
hw = mw / 2
hh = mh / 2
x = 0
v = 0
u = 0
t = 0
k = rnd(190) + 64
set redraw 0
while 1
    set color 0, 0, 0, 255
    draw rect 0, 0, 512, 512, 1
    for i = 0 to 255
        for j= 0 to 255
            u = sin(i + v) + sin(r * i + x)
            v = cos(i + v) + cos(r * i + x)
            x = u + t
            set color i, j, 255 - i, k
            draw pixel int(hw + u * hw * 0.4), int(hh + v * hh * 0.4)
        next
    next
    redraw
    t = t + 0.01
    k = rnd(190) + 64
wend
 
Is this a bug? I've tried draw pixel, set pixel and even both.

Print this item

  Does "everything else" include other programming languages?
Posted by: Tomaaz - 02-07-2024, 03:45 PM - Forum: Everything else - Replies (1)

Recently, I have been banned from a forum and my nickname has been added to censored words, so other users can't even mention my name. So, is it OK to talk here about other languages, projects etc.?

Sorry, I must have had a temporary brain malfunction. Big Grin There is already a section for discussing other languages and programming in general.

Print this item

  No luck with Wine
Posted by: Tomaaz - 02-05-2024, 09:22 AM - Forum: NaaLaa 7 Questions - Replies (9)

So, I've tried to run NaaLaa 7 on Linux, but didn't  have much success. NED runs, but the text is overlapping. That wouldn't be a big problem (as I use Geany with everything), but more complex examples fail to compile an run due to some .dlls missing. I'm aware that NaaLaa is Windows only and the problems have more to do with Wine than NaaLaa itself, but I wonder why much more complex applications run under Wine and NaaLaa doesn't.

Print this item

  Warm Day
Posted by: johnno56 - 02-04-2024, 06:04 PM - Forum: Everything else - Replies (15)

Well, it has taken until 4th of February, for us to get what I call a warm Melbourne summer's day... A very nice 38C... at last... It is rare that we get hot days, 45C+, but it does happen... How warm does it get for other Forum members?

(Well, the forum IS listed as "Everything Else"... I suppose the weather would be included in that category... Moo Ha Ha Ha)

Print this item

  String Command
Posted by: johnno56 - 02-02-2024, 09:40 PM - Forum: NaaLaa 7 Code - Replies (7)

Does N7/6 have the ability or command to perform Basic's string(var, text$) command?

J

In the meantime... I can use something like...

function String(var, txt)
    tmp = ""
    for z = 1 to var
        tmp = tmp + txt
    next
    return tmp
endfunc

Print this item

  PROLAN
Posted by: aurel - 02-02-2024, 04:32 PM - Forum: Programming - Replies (11)

Hi Marcus

I am glad that you have forum back. Smile

Print this item

  my second game, naalaa invader
Posted by: aliensoldier - 02-01-2024, 07:51 PM - Forum: NaaLaa 7 Code - Replies (15)

The game starts on the title screen by pressing the return key to start, the "p" key to pause, the arrow keys to move the ship and the "z" key to shoot. You have to shoot the central square of the enemies to destroy them.

This comment is for Marcus, the game has an error that I have not been able to solve because I don't know what the error is, I have left you a screenshot with the error.
The game sometimes works well and other times the error occurs, it usually happens more times when you beat the game and start a second game again, although it can also happen in the first game and there are times when it doesn't happen and you can beat the game without let nothing happen.



Attached Files
.zip   invader-1.1.zip (Size: 486.67 KB / Downloads: 5)
Print this item

  The json library
Posted by: Marcus - 02-01-2024, 04:40 PM - Forum: NaaLaa 7 Code - Replies (1)

I don't remember if I ever posted something about the json library in the old forum - the one that crashed. But it's very easy to use and can be used for saving and loading most n7 tables. You can read more about the file format here: https://en.wikipedia.org/wiki/JSON

Code:
' json_example.n7
' ---------------
' Using the json library you can turn "any" table into a json string. You can save this string to
' file and load it again to get an exact replica of the original table. So it's a very handy library
' and file format.

include "json.n7"

' Let's say you want to save the player's progress in a game.
data = []
data.lastSaved = time()
data.score = 1349
data.name = "Marcus"
data.level = 5
data.levelScores = [1439, 5131, 1486, 394]
data.position = [x: 10, y: 15]

' Create a file for saving.
f = createfile("savedata.json")
if file(f)
    ' Use JSON_ToString to create a json string and write it to the file.
    write file f, JSON_ToString(data)
    free file f
   
    ' Use JSON_FromFile (there's also JSON_FromString) to load the data into a variable.
    data = JSON_FromFile("savedata.json")
    ' Print out the information loaded from file.
    t = datetime(data.lastSaved)
    pln "lastSaved      = " + t.year + "-" + str(t.month, 2) + "-" + str(t.day, 2) +
            " " + str(t.hour, 2) + ":" + str(t.minute, 2) + ":" + str(t.second)
    pln "score          = " + data.score
    pln "name           = " + data.name
    pln "level          = " + data.level
    pln "levelScores[2] = " + data.levelScores[2]
    pln "position       = " + data.position.x + ", " + data.position.y
else
    pln "Couldn't create file!"
endif

system "pause"

Edit I wrote "most tables". You can assign functions to variabels in an n7 table, and json doesn't support that ofcourse.



Attached Files
.n7   json_example.n7 (Size: 1.39 KB / Downloads: 7)
Print this item