Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows version 1.0.4 released
#1
This is just a minor bug fix.

Objects

Objects can now properly be assigned to object array references in functions. Earlier, a function like the one below would cause a runtime error:

Code:
procedure assign(&objects?[], object?)
  objects[0] = object
endproc


System
For some reason, the system command did absolutely nothing on Windows (although the undocumented shellexecute did), but it's functioning now.

Code:
system "dir & echo hello world & pause"

If you want to capture the output, I suggest you pipe it to a file and read it from there for now:

Code:
' Get a list of files in the current directory.
system "dir /b > temp.txt"
open file 0, "temp.txt"
...


Mouse

set mouse <x>, <y> was a bit bugged but has been fixed now. After calling the command, the mousex() and mousey() functions would return incorrect values until the user moved the mouse and new coordinates were registered.
Reply
#2
(03-24-2019, 12:31 AM)Rick3137 Wrote: Nice fix.

 My computer made me take out the previous version before I could use it.

 Some kind of name conflict.

 The system command opens up a whole new bunch of experiments. For instance it is possible to use the command line while the NaaLaa program is running.

System "cmd"

very cool.


Yeah, the system command is the easy way. But if you need to do stuff in the background, without having a console window popup, you can use the shellexecute command. 

For example, if you want to execute "dir /b *.png > png_files.txt" to put a list of all png files in the current directory into a file png_files.txt (/b strips all information but the actual file names), you could call:



Code:
shellexecute "open", "cmd", "", "/c dir /b *.png > png_files.txt", true

And if you want to create a new folder named doop:

Code:
shellexecute "open", "cmd", "", "/c mkdir doop", true


I believe the syntax is:

Code:
shellexecute <operation>, <file>, <directory>, <parameters>, <wait_until_operation_is_done>

But I'm not quite sure, and I don't have the information available at this moment. It's used in NED to launch the compiler, and that's the only reason the command was added, haha Smile


I have no idea of why the system command hasn't been working for a long time. The C code had actually been commented out, maybe by mistake, who knows. Because I remember using it when dealing with FTP stuff in a naalaa program many years ago.
Reply
#3
I made a small change, fixed a problem with set mouse and updated the installer without changing the version number.
Reply
#4
Yeah, I have to uninstall the old version every time too Sad I'm using some program to generate the installers. Even though only two files have changed and I set it up for patching, the behavior is the same. I must be doing something wrong.
Reply
#5
Great news, thanks for the info and update.
Reply
#6
Yo marcus

and where is download link?
Reply
#7
(04-24-2019, 01:21 PM)Rick3137 Wrote: Hello Marcus:

  While you are still working on key board functions, there are a few that would help for making games. I have been spinning my wheels for several weeks on a game that could use these.

 OnKeyUp( 37 )
 OnKeyDown( 39 )

 I would like to run a procedure when a key is pressed, or released.

NaaLaa does not have a built in "callback" system or "function pointers", so these things can't easily be added.


If you're just interested in using it for a few keys you can get around it with code like this:

Code:
import "Keycodes.lib"
do
 if keydown(VK_SPACE)
  if not spacebarPressed
   spacebarPressed = true
   wln "Spacebar pressed"
  endif
 else
  if spacebarPressed
   spacebarPressed = false
   wln "Spacebar released"
  endif
 endif
 wait 16
until keydown(VK_ESC)
Reply
#8
I wrote a more generic version of the code above. You have to register the keys you want to listen to with RegisterKey, and then call HandleKeys in your program loop. HandleKeys will call KeyDown and KeyUp if the status changes for any of the keys you've registered.

Code:
import "Keycodes.lib"

visible:
    vRegisteredKeys[100]
    vRegisteredKeyCount
    vKeyStatus[100]

hidden:

' Called when a key is pressed.
procedure KeyDown(key)
    wln "Key ", key, " pressed"
endproc

' Called when a key is released.
procedure KeyUp(key)
    wln "Key ", key, " released"
endproc

' Listen for VK_SPACE, VK_LEFT and VK_A
_RegisterKey VK_SPACE
_RegisterKey VK_LEFT
_RegisterKey VK_A

' Loop.
do
    _HandleKeys

    wait 16
loop

' Register a key that you want events for.
procedure RegisterKey(key)
    vRegisteredKeys[vRegisteredKeyCount] = key
    vRegisteredKeyCount = vRegisteredKeyCount + 1
endproc

' Call once per tick in your game loop.
procedure HandleKeys()
    if vRegisteredKeyCount > 0
        for i = 0 to vRegisteredKeyCount - 1
            if keydown(vRegisteredKeys[i])
                if not vKeyStatus[vRegisteredKeys[i]]
                    vKeyStatus[vRegisteredKeys[i]] = true
                    _KeyDown vRegisteredKeys[i]
                endif
            else
                if vKeyStatus[vRegisteredKeys[i]]
                    vKeyStatus[vRegisteredKeys[i]] = false
                    _KeyUp vRegisteredKeys[i]
                endif
            endif
        next
    endif
endproc

Hope it helps Smile


Note, that if you pause your program with wait, wait keydown or wait mousebutton the KeyDown and KeyUp functions won't be triggered until the next time you call HandleKeys. If you need to get around this, I suggest you write your own versions of these commands that use loops. Example:


Code:
' Wait with key events.
procedure Wait(ms)
    t = time() + ms
    do
        _HandleKeys
        wait 1
    until time() >= t
endproc
Reply
#9
Hello Marcus,

There will be a new version of NAALAA in the next months ? (I hope)

Your language need more advertising, it is great....

I want the same NAALAA with an optimized IDE (no lines limit) Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)