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

  • Thread starter Thread starter Rinnegatamante
  • Start date Start date
  • Views Views 187,228
  • Replies Replies 1,199
  • Likes Likes 35
How can I make it so that when a button is pressed a wav plays?
Code:
pad = Controls.read()
    if (Controls.check(pad,KEY_A)) then
    Sound.play(audio,NO_LOOP,0x09)
The code above gives me an error. I have set "audio" to = something, and playing the audio w/o a button combo works fine.
 
  • Like
Reactions: Seriel
How can I make it so that when a button is pressed a wav plays?
Code:
pad = Controls.read()
    if (Controls.check(pad,KEY_A)) then
    Sound.play(audio,NO_LOOP,0x09)
The code above gives me an error. I have set "audio" to = something, and playing the audio w/o a button combo works fine.
What error do you get?
 
  • Like
Reactions: Seriel
Alright so I wrote up this program as a simple calculator, and it works perfectly fine on citra (other than the pictures appearing as a glitch for some reason) but when I run it on my 3ds it's a black screen on both the top and bottom screens...

Code:
white = Color.new(255, 255, 255)
num1 = 0
num2 = 0
operation = 1
answer = 0
remainder = 0
oldpad = Controls.read()
uparrow = Screen.loadImage("/up.bmp")
downarrow = Screen.loadImage("/down.bmp")
while true do
    Screen.refresh()
    pad = Controls.read()
    x,y = Controls.readTouch()
    Screen.clear(TOP_SCREEN)
    Screen.clear(BOTTOM_SCREEN)
    if (Controls.check(pad,KEY_DUP)) and not (Controls.check(oldpad,KEY_DUP)) then
        num1 = num1 + 1
    end
    if (Controls.check(pad,KEY_DDOWN)) and not (Controls.check(oldpad,KEY_DDOWN)) then
        num1 = num1 - 1
    end
    if (Controls.check(pad,KEY_DRIGHT)) and not (Controls.check(oldpad,KEY_DRIGHT)) then
        num2 = num2 + 1
    end
    if (Controls.check(pad,KEY_DLEFT)) and not (Controls.check(oldpad,KEY_DLEFT)) then
        num2 = num2 - 1
    end
    if(Controls.check(pad,KEY_TOUCH)) and not (Controls.check(oldpad, KEY_TOUCH)) then
        x,y = Controls.readTouch()
        if(x > 19) and (x < 99) and (y > 30) and (y < 55) then
            num1 = num1 + 1
        elseif(x > 19) and (x < 99) and (y > 160) and (y < 185) then
            num1 = num1 - 1
        elseif(x > 119) and (x < 199) and (y > 30) and (y < 55) then
            if operation == 5 then
                operation = 1
            else
                operation = operation + 1
            end
        elseif(x > 119) and (x < 199) and (y > 160) and (y < 185) then
            if operation == 1 then
                operation = 5
            else
                operation = operation - 1
            end
        elseif(x > 219) and (x < 299) and (y > 30) and (y < 55) then
            num2 = num2 + 1
        elseif(x > 219) and (x < 299) and (y > 160) and (y < 185) then
            num2 = num2 - 1
        end
    end
    if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) then
        operation = 1
        answer = num1 + num2
    end
    if (Controls.check(pad,KEY_B)) and not (Controls.check(oldpad,KEY_B)) then
        operation = 2
        answer = num1 - num2
    end
    if (Controls.check(pad,KEY_Y)) and not (Controls.check(oldpad,KEY_Y)) then
        operation = 3
        if num2 > 0 then
            answer = num1 // num2
            remainder = num1 % num2
        end
    end
    if (Controls.check(pad,KEY_X)) and not (Controls.check(oldpad,KEY_X)) then
        operation = 4
        answer = num1 * num2
    end
    if (Controls.check(pad,KEY_SELECT)) and not (Controls.check(oldpad,KEY_SELECT)) then
        operation = 5
        answer = num1 ^ num2
    end
    if (Controls.check(pad, KEY_START)) then
        System.exit()
    end
    Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
    Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
    Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
    Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
    Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
    Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
    if operation == 1 then
        answer = num1 + num2
        Screen.debugPrint(0,30,num1 .. " + " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 2 then
        answer = num1 - num2
        Screen.debugPrint(0,30,num1 .. " - " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 3 then
        if num2 ~= 0 then
            answer = num1 // num2
            remainder = num1 % num2
            if remainder ~= 0 then
                Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = " .. answer .. "r" .. remainder,white,TOP_SCREEN)
            else
                Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = " .. answer,white,TOP_SCREEN)
            end
        else
            Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = UNDEFINED",white,TOP_SCREEN)
        end
    elseif operation == 4 then
        answer = num1 * num2
        Screen.debugPrint(0,30,num1 .. " x " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 5 then
        answer = num1 ^ num2
        Screen.debugPrint(0,30,num1 .. "^" .. num2 .. " = " .. answer,white,TOP_SCREEN)
    end
    Screen.flip()
    oldpad = pad
    Screen.waitVblankStart()
end

Here's up.bmp and down.bmp: http://imgur.com/a/syCtr

EDIT: The touch screen part does work just fine, it's just the image is glitched
 
Alright so I wrote up this program as a simple calculator, and it works perfectly fine on citra (other than the pictures appearing as a glitch for some reason) but when I run it on my 3ds it's a black screen on both the top and bottom screens...

Code:
white = Color.new(255, 255, 255)
num1 = 0
num2 = 0
operation = 1
answer = 0
remainder = 0
oldpad = Controls.read()
uparrow = Screen.loadImage("/up.bmp")
downarrow = Screen.loadImage("/down.bmp")
while true do
    Screen.refresh()
    pad = Controls.read()
    x,y = Controls.readTouch()
    Screen.clear(TOP_SCREEN)
    Screen.clear(BOTTOM_SCREEN)
    if (Controls.check(pad,KEY_DUP)) and not (Controls.check(oldpad,KEY_DUP)) then
        num1 = num1 + 1
    end
    if (Controls.check(pad,KEY_DDOWN)) and not (Controls.check(oldpad,KEY_DDOWN)) then
        num1 = num1 - 1
    end
    if (Controls.check(pad,KEY_DRIGHT)) and not (Controls.check(oldpad,KEY_DRIGHT)) then
        num2 = num2 + 1
    end
    if (Controls.check(pad,KEY_DLEFT)) and not (Controls.check(oldpad,KEY_DLEFT)) then
        num2 = num2 - 1
    end
    if(Controls.check(pad,KEY_TOUCH)) and not (Controls.check(oldpad, KEY_TOUCH)) then
        x,y = Controls.readTouch()
        if(x > 19) and (x < 99) and (y > 30) and (y < 55) then
            num1 = num1 + 1
        elseif(x > 19) and (x < 99) and (y > 160) and (y < 185) then
            num1 = num1 - 1
        elseif(x > 119) and (x < 199) and (y > 30) and (y < 55) then
            if operation == 5 then
                operation = 1
            else
                operation = operation + 1
            end
        elseif(x > 119) and (x < 199) and (y > 160) and (y < 185) then
            if operation == 1 then
                operation = 5
            else
                operation = operation - 1
            end
        elseif(x > 219) and (x < 299) and (y > 30) and (y < 55) then
            num2 = num2 + 1
        elseif(x > 219) and (x < 299) and (y > 160) and (y < 185) then
            num2 = num2 - 1
        end
    end
    if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) then
        operation = 1
        answer = num1 + num2
    end
    if (Controls.check(pad,KEY_B)) and not (Controls.check(oldpad,KEY_B)) then
        operation = 2
        answer = num1 - num2
    end
    if (Controls.check(pad,KEY_Y)) and not (Controls.check(oldpad,KEY_Y)) then
        operation = 3
        if num2 > 0 then
            answer = num1 // num2
            remainder = num1 % num2
        end
    end
    if (Controls.check(pad,KEY_X)) and not (Controls.check(oldpad,KEY_X)) then
        operation = 4
        answer = num1 * num2
    end
    if (Controls.check(pad,KEY_SELECT)) and not (Controls.check(oldpad,KEY_SELECT)) then
        operation = 5
        answer = num1 ^ num2
    end
    if (Controls.check(pad, KEY_START)) then
        System.exit()
    end
    Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
    Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
    Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
    Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
    Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
    Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
    if operation == 1 then
        answer = num1 + num2
        Screen.debugPrint(0,30,num1 .. " + " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 2 then
        answer = num1 - num2
        Screen.debugPrint(0,30,num1 .. " - " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 3 then
        if num2 ~= 0 then
            answer = num1 // num2
            remainder = num1 % num2
            if remainder ~= 0 then
                Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = " .. answer .. "r" .. remainder,white,TOP_SCREEN)
            else
                Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = " .. answer,white,TOP_SCREEN)
            end
        else
            Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = UNDEFINED",white,TOP_SCREEN)
        end
    elseif operation == 4 then
        answer = num1 * num2
        Screen.debugPrint(0,30,num1 .. " x " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 5 then
        answer = num1 ^ num2
        Screen.debugPrint(0,30,num1 .. "^" .. num2 .. " = " .. answer,white,TOP_SCREEN)
    end
    Screen.flip()
    oldpad = pad
    Screen.waitVblankStart()
end

Here's up.bmp and down.bmp: http://imgur.com/a/syCtr

EDIT: The touch screen part does work just fine, it's just the image is glitched

Try to use JPG / PNG images and check if paths are fine.
 
  • Like
Reactions: Seriel
Code:
uparrow = Screen.loadImage("/up.bmp")
downarrow = Screen.loadImage("/down.bmp")
This is trying to load the images from the root of the SD card, which is probably not where they are when you use a .3dsx. Try this:
Code:
uparrow = Screen.loadImage(System.currentDirectory().."/up.bmp")
downarrow = Screen.loadImage(System.currentDirectory().."/down.bmp")
 
  • Like
Reactions: Seriel
what is exactly lua player plus and how install?

To put it simply: lua player plus is a 3dsx file (Homebrew Launcher executable) that will find and run the file "index.lua" when launched.

As index.lua will be a Lua file (obviously) you can type any Lua code you want into it and it will be executed.

3dsx files must be placed in their own folder which must also be named after the 3dsx file it contains, and this folder must be inside the root/3ds/ folder.
Example:
Code:
root/3ds/example/example.3dsx
 
Last edited by HexZyle,
  • Like
Reactions: Seriel and Jwiz33
So I changed the bmp to png and added some new code and it works fine on citra but still just shows a black screen on my 3DS...

Code:
white = Color.new(255, 255, 255)
num1 = 0
num2 = 0
operation = 1
answer = 0
remainder = 0
oldpad = Controls.read()
uparrow = Screen.loadImage("/up.png")
downarrow = Screen.loadImage("/down.png")
while true do
    Screen.refresh()
    pad = Controls.read()
    x,y = Controls.readTouch()
    Screen.clear(TOP_SCREEN)
    Screen.clear(BOTTOM_SCREEN)
    if (Controls.check(pad,KEY_DUP)) and not (Controls.check(oldpad,KEY_DUP)) then
        num1 = num1 + 1
    end
    if (Controls.check(pad,KEY_DDOWN)) and not (Controls.check(oldpad,KEY_DDOWN)) then
        num1 = num1 - 1
    end
    if (Controls.check(pad,KEY_DRIGHT)) and not (Controls.check(oldpad,KEY_DRIGHT)) then
        num2 = num2 + 1
    end
    if (Controls.check(pad,KEY_DLEFT)) and not (Controls.check(oldpad,KEY_DLEFT)) then
        num2 = num2 - 1
    end
    if(Controls.check(pad,KEY_TOUCH)) and not (Controls.check(oldpad, KEY_TOUCH)) then
        x,y = Controls.readTouch()
        if(x > 19) and (x < 99) and (y > 30) and (y < 55) then
            num1 = num1 + 1
        elseif(x > 19) and (x < 99) and (y > 160) and (y < 185) then
            num1 = num1 - 1
        elseif(x > 119) and (x < 199) and (y > 30) and (y < 55) then
            if operation == 5 then
                operation = 1
            else
                operation = operation + 1
            end
        elseif(x > 119) and (x < 199) and (y > 160) and (y < 185) then
            if operation == 1 then
                operation = 5
            else
                operation = operation - 1
            end
        elseif(x > 219) and (x < 299) and (y > 30) and (y < 55) then
            num2 = num2 + 1
        elseif(x > 219) and (x < 299) and (y > 160) and (y < 185) then
            num2 = num2 - 1
        end
    end
    if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) then
        operation = 1
        answer = num1 + num2
    end
    if (Controls.check(pad,KEY_B)) and not (Controls.check(oldpad,KEY_B)) then
        operation = 2
        answer = num1 - num2
    end
    if (Controls.check(pad,KEY_Y)) and not (Controls.check(oldpad,KEY_Y)) then
        operation = 3
        if num2 > 0 then
            answer = num1 // num2
            remainder = num1 % num2
        end
    end
    if (Controls.check(pad,KEY_X)) and not (Controls.check(oldpad,KEY_X)) then
        operation = 4
        answer = num1 * num2
    end
    if (Controls.check(pad,KEY_SELECT)) and not (Controls.check(oldpad,KEY_SELECT)) then
        operation = 5
        answer = num1 ^ num2
    end
    if (Controls.check(pad, KEY_START)) then
        System.exit()
    end
   
    if(Controls.check(pad,KEY_TOUCH)) then
        x,y = Controls.readTouch()
        if(x > 19) and (x < 99) and (y > 30) and (y < 55) then
            Screen.drawImage(20,33,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
        elseif(x > 19) and (x < 99) and (y > 160) and (y < 185) then
            Screen.drawImage(20,163,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
        elseif(x > 119) and (x < 199) and (y > 30) and (y < 55) then
            Screen.drawImage(120,33,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
        elseif(x > 119) and (x < 199) and (y > 160) and (y < 185) then
            Screen.drawImage(120,163,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
        elseif(x > 219) and (x < 299) and (y > 30) and (y < 55) then
            Screen.drawImage(220,33,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
        elseif(x > 219) and (x < 299) and (y > 160) and (y < 185) then
            Screen.drawImage(220,163,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
        else
            Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
            Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
            Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
        end
    else
        Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
        Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
        Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
        Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
        Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
        Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
    end
    if operation == 1 then
        answer = num1 + num2
        Screen.debugPrint(0,30,num1 .. " + " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 2 then
        answer = num1 - num2
        Screen.debugPrint(0,30,num1 .. " - " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 3 then
        if num2 ~= 0 then
            answer = num1 // num2
            remainder = num1 % num2
            if remainder ~= 0 then
                Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = " .. answer .. "r" .. remainder,white,TOP_SCREEN)
            else
                Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = " .. answer,white,TOP_SCREEN)
            end
        else
            Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = UNDEFINED",white,TOP_SCREEN)
        end
    elseif operation == 4 then
        answer = num1 * num2
        Screen.debugPrint(0,30,num1 .. " x " .. num2 .. " = " .. answer,white,TOP_SCREEN)
    elseif operation == 5 then
        answer = num1 ^ num2
        Screen.debugPrint(0,30,num1 .. "^" .. num2 .. " = " .. answer,white,TOP_SCREEN)
    end
    Screen.flip()
    oldpad = pad
    Screen.waitVblankStart()
end

Here's up.ong and down.png if you need it: http://imgur.com/a/syCtr
 
  • Like
Reactions: Seriel
So I changed the bmp to png and added some new code and it works fine on citra but still just shows a black screen on my 3DS...

-snip-

Here's up.ong and down.png if you need it: http://imgur.com/a/syCtr

You've been responded to multiple times with solutions to your issue:


I had the same problem. You need to use the absolute path for files.

you could try 'dofile(System.currentDirectory().."/graphics_and_controls.lua")'.

From page 15 of this thread.

Try to use JPG / PNG images and check if paths are fine.

This is trying to load the images from the root of the SD card, which is probably not where they are when you use a .3dsx. Try this:
Code:
uparrow = Screen.loadImage(System.currentDirectory().."/up.bmp")
downarrow = Screen.loadImage(System.currentDirectory().."/down.bmp")
 
I'm scrolling back in the post and I can't see a single one of those posts :/

Either way thanks!

Try refreshing the page. This forum engine can be weird when it comes to posting from previous pages, or people posting new things since you refreshed.
 
  • Like
Reactions: Seriel

Site & Scene News

Popular threads in this forum