Homebrew [Release] Lua Player Plus 3DS (lpp-3ds) - LUA interpreter for 3DS

Rinnegatamante

Well-Known Member
OP
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
Good to know and helpful, changes the way I code most of this, but I seem to still have the same problem.

Made some basic test code, ran by itself, to try to isolate the problem.

Code:
Socket.init()
client = 0
while client == 0 do
  client = Socket.connect("192.168.1.201", 6667)
end
Socket.send(client, "TEST")
Socket.close(client)
Socket.term()
while true do
  if Controls.check(Controls.read(), KEY_START) then
    System.exit()
  end
end

Behavior seems to depend on lpp-3ds version.

On R4 and the november nightly:

Error: [string "?"]:4: Failed connecting server.

However, on current git:

Error: [string "?"]:6: bad argument #1 to 'send' (number expected, got nil)

This seems to imply that if it can't connect, as of the current git instead of throwing up an error it returns nil. Which is handy, but if I test for that then I just get to debugprint my own way of saying "Connection failed."

On the receiving end, I occasionally get half-open connections which cause netcat to quit as though something connected to it and then left, but mostly seem to get nothing.

Since I did get the net_request_string sample working, I decided to try this just once, seeing as it's contacting the same server:

Code:
Socket.init()
client = 0
while client == 0 do
  client = Socket.connect("rinnegatamante.netsons.org", 80)
end
Socket.send(client, "GET /\r\n")
Socket.close(client)
Socket.term()
while true do
  if Controls.check(Controls.read(), KEY_START) then
  System.exit()
  end
end

Exact same result, either "Failed connecting server" or an attempt to send to a nil socket, depending on lpp-3ds version.

There isn't a DNS resolver right now for hostnames resolutions. Try to change the while loop condition from client == 0 to client == nil
 

Insidious611

Well-Known Member
Member
Joined
Oct 23, 2010
Messages
167
Trophies
1
XP
343
Country
United States
Hmm... alright. I have two questions though. If I'm just looping around reconnecting whenever I get nil, how do I detect a legitimately failed connection, like a connection refused or a timeout?

The second... Using this code now:

Code:
Socket.init()
client = nil
while client == nil do
  client = Socket.connect("192.168.1.201", 6667)
end
Socket.send(client, "TEST\r\n")
timer = Timer.new()
mytime = Timer.getTime(timer)
while mytime < 5000 do
  Screen.waitVblankStart()
  mytime = Timer.getTime(timer)
end
Socket.close(client)
Socket.term()
while true do
  if Controls.check(Controls.read(), KEY_START) then
  System.exit()
  end
end

I can get a definite connection, but no packets seem to actually be sent. I added the timer because I thought maybe this was due to me not giving enough time for the nonblocking I/O to complete before closing the socket, but even after 5 full seconds the server has received no packets. So err, what's going on now? :P

EDIT: Okay, nevermind the second bit. Apparently that was down to netcat for once, I wiresharked it and the packets are being sent.
 
Last edited by Insidious611,

PabloMK7

Red Yoshi! ^ω^
Developer
Joined
Feb 21, 2014
Messages
2,616
Trophies
2
Age
24
Location
Yoshi's Island
XP
5,172
Country
Spain
I'm trying to use System.listDirectory(System.currentDirectory().."gamefs/Course"), to list the files inside a folder, can someone tell me the useage, because it isn't working.
 

ihaveahax

Well-Known Member
Member
Joined
Apr 20, 2015
Messages
6,070
Trophies
2
XP
7,854
Country
United States
I'm trying to use System.listDirectory(System.currentDirectory().."gamefs/Course"), to list the files inside a folder, can someone tell me the useage, because it isn't working.
Code:
System.listDirectory(System.currentDirectory().."/gamefs/Course")
note the extra /
 

PabloMK7

Red Yoshi! ^ω^
Developer
Joined
Feb 21, 2014
Messages
2,616
Trophies
2
Age
24
Location
Yoshi's Island
XP
5,172
Country
Spain
I noticed it, but still the same, if I list the number of entries, it gives me the correct number.
I want the filenames, f. ex: Gctr_ToadCircuit.szs.

I read at Organiz3d source, and I see its usage is "strange". Could anyone tell me how it works? :S
 
Last edited by PabloMK7,

ihaveahax

Well-Known Member
Member
Joined
Apr 20, 2015
Messages
6,070
Trophies
2
XP
7,854
Country
United States
I noticed it, but still the same, if I list the number of entries, it gives me the correct number.
I want the filenames, f. ex: Gctr_ToadCircuit.szs.
Code:
list = System.listDirectory(System.currentDirectory().."/gamefs/Course")
for k, v in pairs(list) do
    -- do something with v.name, v.size, and v.directory (is it a directory?)
end
 
  • Like
Reactions: PabloMK7

ihaveahax

Well-Known Member
Member
Joined
Apr 20, 2015
Messages
6,070
Trophies
2
XP
7,854
Country
United States
Is there any way to order the files alphabetically, or are they already alphabetically ordered?
try this. I haven't actually tested it but it should work. I remember reading something like this from the ORGANIZ3D source...
Code:
list = System.listDirectory(System.currentDirectory().."/gamefs/Course")
table.sort(list, function (a, b) return (a.name:lower() < b.name:lower() ) end)
 

PabloMK7

Red Yoshi! ^ω^
Developer
Joined
Feb 21, 2014
Messages
2,616
Trophies
2
Age
24
Location
Yoshi's Island
XP
5,172
Country
Spain
I'm having troubles with file listing, I used this code (from Organiz3d source):
Code:
System.currentDirectory("/CTGP-7/")
function TableConcat(t1,t2)
    for i=1,#t2 do
        t1[#t1+1] = t2[i]
    end
    return t1
end
function getfilename(dir)
    folders_table = {}
    files_table = {}
    for i,file in pairs(dir) do
        if file.directory then
            table.insert(folders_table,file)
        else
            table.insert(files_table,file)
        end
    end
    table.sort(files_table, function (a, b) return (a.name:lower() < b.name:lower() ) end)
    table.sort(folders_table, function (a, b) return (a.name:lower() < b.name:lower() ) end)
    return_table = TableConcat(folders_table,files_table)
    return return_table
end
filenames = getfilename(System.listDirectory(System.currentDirectory().."gamefs/Course"))
while true do
Screen.debugPrint(0, 20, filenames[1].name, Color.new(255,255,255),TOP_SCREEN)
end
It's not printing anything.
 
Last edited by PabloMK7,

Rinnegatamante

Well-Known Member
OP
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
I'm having troubles with file listing, I used this code (from Organiz3d source):
Code:
System.currentDirectory("/CTGP-7/")
function TableConcat(t1,t2)
    for i=1,#t2 do
        t1[#t1+1] = t2[i]
    end
    return t1
end
function getfilename(dir)
    folders_table = {}
    files_table = {}
    for i,file in pairs(dir) do
        if file.directory then
            table.insert(folders_table,file)
        else
            table.insert(files_table,file)
        end
    end
    table.sort(files_table, function (a, b) return (a.name:lower() < b.name:lower() ) end)
    table.sort(folders_table, function (a, b) return (a.name:lower() < b.name:lower() ) end)
    return_table = TableConcat(folders_table,files_table)
    return return_table
end
filenames = getfilename(System.listDirectory(System.currentDirectory().."gamefs/Course"))
while true do
Screen.debugPrint(0, 20, filenames[1].name, Color.new(255,255,255),TOP_SCREEN)
end
It's not printing anything.

You never call waitVblankStart, flip and refresh.
 

Biont

Member
Newcomer
Joined
Jan 18, 2016
Messages
7
Trophies
0
Age
124
XP
64
Country
Barbados
Hello and thank you for this amazing library. It's incredibly easy to get started with and I am having loads of fun.
I have been looking for a good excuse to finally try something in Lua for a while and it feels great to do so on a hacked N3DS (which I bought a few days ago)

2 Questions:
1:
Would you recommend implementing some kind of spritesheet/textureatlas when using the Graphics module? I mean having most many different graphics on a single bitmap grid and then making generous use of drawPartialImage/drawImageExtended to render out a portion of it? Is it a good idea to do something like that or is there some unwanted overhead to the extended Graphics methods?
I'm creating a match-3-puzzler, so having all "gems" in some sort of single-image-grid sounded like an obvious choice

Feel free to accuse me of premature optimization, but Citra is giving me ~0.5fps while my N3DS still breezes through it.
Before I settle for the unfortunate (albeit obvious) solution to do my 3DS tinkering on my powerful work PC (which is something I wanted to escape after a workday), I just wanted to know if there's something wrong with my approach in general


2:
Is there any way to use 3D effects while using the GPU? Only the Screen methods seem to support depth right now.
 

Rinnegatamante

Well-Known Member
OP
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
Hello and thank you for this amazing library. It's incredibly easy to get started with and I am having loads of fun.
I have been looking for a good excuse to finally try something in Lua for a while and it feels great to do so on a hacked N3DS (which I bought a few days ago)

2 Questions:
1:
Would you recommend implementing some kind of spritesheet/textureatlas when using the Graphics module? I mean having most many different graphics on a single bitmap grid and then making generous use of drawPartialImage/drawImageExtended to render out a portion of it? Is it a good idea to do something like that or is there some unwanted overhead to the extended Graphics methods?
I'm creating a match-3-puzzler, so having all "gems" in some sort of single-image-grid sounded like an obvious choice

Feel free to accuse me of premature optimization, but Citra is giving me ~0.5fps while my N3DS still breezes through it.
Before I settle for the unfortunate (albeit obvious) solution to do my 3DS tinkering on my powerful work PC (which is something I wanted to escape after a workday), I just wanted to know if there's something wrong with my approach in general


2:
Is there any way to use 3D effects while using the GPU? Only the Screen methods seem to support depth right now.

I suggest you to use the lowest number of images you can cause rendering a part or a full image are the same GPU intensive but loading lower number of images will result in a lower loading time obviously.
For the 3D effect, it's completely usable also for Graphics module. you can use it by enabling it with Screen.enable3D() and then use Graphics.initBlend(TOP_SCREEN, LEFT_EYE) and Graphics.initBlend(TOP_SCREEN, RIGHT_EYE) to blend on different framebuffers.

If you're looking on a 3D Game Engine, i recently released also Lua RayCast3D for lpp-3ds which allows you to make 3D games with a pretty simple engine working on lpp-3ds: https://gbatemp.net/threads/w-i-p-lua-raycast3d-3d-game-engine-for-lpp-3ds.407381/

A game created using it is Labyrinth 3D: http://gbatemp.net/threads/re-release-labyrinth-3d.409007/
 

Biont

Member
Newcomer
Joined
Jan 18, 2016
Messages
7
Trophies
0
Age
124
XP
64
Country
Barbados
I suggest you to use the lowest number of images you can cause rendering a part or a full image are the same GPU intensive but loading lower number of images will result in a lower loading time obviously.

So I assume that's a "yes" to using a texture atlas, then.

For the 3D effect, it's completely usable also for Graphics module. you can use it by enabling it with Screen.enable3D() and then use Graphics.initBlend(TOP_SCREEN, LEFT_EYE) and Graphics.initBlend(TOP_SCREEN, RIGHT_EYE) to blend on different framebuffers.
Ah! I missed that argument for initBlend(). Might have taken the hint if I had noticed it. Thank you, this looks just like what I need

If you're looking on a 3D Game Engine, i recently released also Lua RayCast3D for lpp-3ds which allows you to make 3D games with a pretty simple engine working on lpp-3ds: https://gbatemp.net/threads/w-i-p-lua-raycast3d-3d-game-engine-for-lpp-3ds.407381/

A game created using it is Labyrinth 3D: http://gbatemp.net/threads/re-release-labyrinth-3d.409007/
Whoa. I will have to check those out! Haven't noticed them yet. Great work.

Thank you for your reply and keep up the great work.
 

Biont

Member
Newcomer
Joined
Jan 18, 2016
Messages
7
Trophies
0
Age
124
XP
64
Country
Barbados
I am getting errors in Citra whenever I call table.getn()
Does that ring any bell? I'm reading that this is essential for iterating over tables and ZeroBrane does not give me any errors. What am I doing wrong?

It says "attempt to call a nil value (fields 'get0/"
 
Last edited by Biont,

GalladeGuy

Cool and Epic
Member
Joined
Oct 28, 2015
Messages
2,686
Trophies
1
XP
3,115
Country
United States
Can someone please help me? Whenever I try making a program that prints an image, it gives me an error. Even the image example gives me an error. Is this a bug? Or am I just being stupid? Here is the error:

Code:
Error: [string "?"]:6: attempt to access wrong memory block type

And here's the code from the image example:

Code:
white = Color.new(255,255,255)
black = Color.new(0,0,0)
oldpad = Controls.read()
bitmap2 = Screen.loadImage("/file.bmp")
bitmap = Screen.createImage(1,1,black)
Screen.flipImage(bitmap2,bitmap)
Screen.fillRect(50,150,1,15,white,bitmap2)
Screen.debugPrint(51,3,"Image...OK!",black,bitmap2)
while true do
    Screen.waitVblankStart()
    Screen.refresh()
    pad = Controls.read()
    if (Controls.check(pad,KEY_A)) then
        System.exit()
    end
    if (Controls.check(pad,KEY_B)) and not (Controls.check(oldpad,KEY_B)) then
        Screen.saveBitmap(bitmap2,"/bitmap.bmp")
        System.takeScreenshot("/screenshot.bmp",false)
    end
    Screen.drawImage(100,127,bitmap2,TOP_SCREEN)
    Screen.drawImage(60,0,bitmap,BOTTOM_SCREEN)
    Screen.flip()
    oldpad = pad
end
 
Last edited by GalladeGuy,

Biont

Member
Newcomer
Joined
Jan 18, 2016
Messages
7
Trophies
0
Age
124
XP
64
Country
Barbados
Can someone please help me? Whenever I try making a program that prints an image, it gives me an error. Even the image example gives me an error. Is this a bug? Or am I just being stupid? Here is the error:

Code:
Error: [string "?"]:6: attempt to access wrong memory block type

I can't see the issue in your specific code, but I am aware of to causes for the error you're getting:

- Using the wrong module (loading an image from the Screen module, but accessing it from the Graphics module). There's a converter method for this use case
- Using a wrong file name. In my case, I accidentally tried to load a .bmp when the file was actually a .png, because I did not properly look at the file I was using. But maybe a simply non-existing file triggers that kind of error as well.

So since you're not mixing Screen/Graphics modules, I'd say have a very close look at your filename and see if it actually points to the file you're trying to load
 
  • Like
Reactions: GalladeGuy

Rinnegatamante

Well-Known Member
OP
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
I am getting errors in Citra whenever I call table.getn()
Does that ring any bell? I'm reading that this is essential for iterating over tables and ZeroBrane does not give me any errors. What am I doing wrong?

It says "attempt to call a nil value (fields 'get0/"

getn method has been removed by Lua 5.2. If you want to know the number of elements in your table, you now have to use the # function. Example:
Code:
table = {1, 2, 3, 4, 5}
num_elements_in_table = #table
 

GalladeGuy

Cool and Epic
Member
Joined
Oct 28, 2015
Messages
2,686
Trophies
1
XP
3,115
Country
United States
I can't see the issue in your specific code, but I am aware of to causes for the error you're getting:

- Using the wrong module (loading an image from the Screen module, but accessing it from the Graphics module). There's a converter method for this use case
- Using a wrong file name. In my case, I accidentally tried to load a .bmp when the file was actually a .png, because I did not properly look at the file I was using. But maybe a simply non-existing file triggers that kind of error as well.

So since you're not mixing Screen/Graphics modules, I'd say have a very close look at your filename and see if it actually points to the file you're trying to load
Thanks! Turns out, I had the filepath pointing to the root of the SD Card, even though they were in the actual folder. Kind of a stupid mistake. :P
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • SylverReZ @ SylverReZ:
    @mthrnite, Cheetah Girls, the sequel to Action 52's Cheetah Men.
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    Pokemon Black I played that one a lot
  • K3Nv2 @ K3Nv2:
    Honestly never messed with Pokémon on ds much
  • mthrnite @ mthrnite:
    I played pokemon once, was bored, never tried again
  • Psionic Roshambo @ Psionic Roshambo:
    Oh Dragon Quest IX
  • K3Nv2 @ K3Nv2:
    Spent like 5 hours on switch one never touched it again
  • Psionic Roshambo @ Psionic Roshambo:
    Sentinel of the stary skies
  • K3Nv2 @ K3Nv2:
    Ds is 20 years old this year
  • Psionic Roshambo @ Psionic Roshambo:
    So MJ no longer wants to play with it?
  • K3Nv2 @ K3Nv2:
    He put it down when the 3ds came out
  • SylverReZ @ SylverReZ:
    @K3Nv2, RIP Felix does great videos on the PS3 yellow-light-of-death.
  • Jayro @ Jayro:
    Eventhough the New 3DS XL is more powerful, I still feel like the DS Lite was a more polished system. It's a real shame that it never got an XL variant keeping the GBA slot. You'd have to go on AliExpress and buy an ML shell to give a DS phat the unofficial "DS Lite" treatment, and that's the best we'll ever get I'm afraid.
    +1
  • Jayro @ Jayro:
    The phat model had amazingly loud speakers tho.
    +1
  • SylverReZ @ SylverReZ:
    @Jayro, I don't see whats so special about the DS ML, its just a DS lite in a phat shell. At least the phat model had louder speakers, whereas the lite has a much better screen.
    +1
  • SylverReZ @ SylverReZ:
    They probably said "Hey, why not we combine the two together and make a 'new' DS to sell".
  • Veho @ Veho:
    It's a DS Lite in a slightly bigger DS Lite shell.
    +1
  • Veho @ Veho:
    It's not a Nintendo / iQue official product, it's a 3rd party custom.
    +1
  • Veho @ Veho:
    Nothing special about it other than it's more comfortable than the Lite
    for people with beefy hands.
    +1
  • Jayro @ Jayro:
    I have yaoi anime hands, very lorge but slender.
  • Jayro @ Jayro:
    I'm Slenderman.
  • Veho @ Veho:
    I have hands.
    Veho @ Veho: +1