Homebrew [Release] - LövePotion - LÖVE API for 3DS Homebrew - BETA

XavyrrVaati

Hobbyist programmer?
Member
Joined
Feb 23, 2014
Messages
385
Trophies
0
XP
478
Country
United States
Ahhh, I was using .lua, no wonder. Thanks both of you!
EDIT: Lol, I got a half error screen. Left eye sees the error, right eye sees what I want it to, lmao. Trippy.
 
Last edited by XavyrrVaati,
  • Like
Reactions: VideahGams

Tobold

Member
Newcomer
Joined
Jan 13, 2016
Messages
8
Trophies
0
Age
40
XP
52
Country
Gambia, The
Yup, I use it like this:

Code:
require("stuff.stuff.code")

You don't have to write a full path, the points are used as separators, and you don't have to write .lua.

Seperators in what way? In your example, would the full path be:
Code:
/3ds/lovepotion/game/stuff/stuff/code.lua
?
 

Tobold

Member
Newcomer
Joined
Jan 13, 2016
Messages
8
Trophies
0
Age
40
XP
52
Country
Gambia, The
Is there a way for my program to tell if it runs on a 3DS?
Would be cool if it could configure itself on the fly instead of me making different packages.
 

haazet

Well-Known Member
Newcomer
Joined
Dec 15, 2015
Messages
64
Trophies
0
XP
159
Country
United States
Substance's Sig reminds me I cant build my project for the life of me. I followed the tutorial linked on the github. I run the make file and it builds until it gets to linking build.elf part and it says i was missing things in my devkitARM\arm-none-eabi like libpng and libjpeg. So I installed those portlibs and that message went away but now its saying I dont have libsf2d and libsfil.

Anyone wants to try it out here is the Main and assets to run. Still needs a lot of work
http://giphy.com/gifs/3o6UB9fUwC82bnWqsg
http://s000.tinyupload.com/index.php?file_id=79154826757403831196
 

Substance12

Well-Known Member
Member
Joined
Aug 2, 2015
Messages
562
Trophies
0
XP
549
Country
Argentina
Substance's Sig reminds me I cant build my project for the life of me. I followed the tutorial linked on the github. I run the make file and it builds until it gets to linking build.elf part and it says i was missing things in my devkitARM\arm-none-eabi like libpng and libjpeg. So I installed those portlibs and that message went away but now its saying I dont have libsf2d and libsfil.

Anyone wants to try it out here is the Main and assets to run. Still needs a lot of work
http://giphy.com/gifs/3o6UB9fUwC82bnWqsg
http://s000.tinyupload.com/index.php?file_id=79154826757403831196

Are you on Windows? I made a guide for compiling under Windows a couple days ago:

https://github.com/VideahGams/LovePotion/wiki/Building-LÖVEPotion
 

Substance12

Well-Known Member
Member
Joined
Aug 2, 2015
Messages
562
Trophies
0
XP
549
Country
Argentina
@VideahGams
I setup the font for use, and tried to make it draw "Hello World!"
But i get two white screens..
Could anyone help me with this issue i seem to be having? If they could i would greatly appreciate it.

Your problem is that it's drawing both the background and the text in white. Your code should be like this:


Code:
function love.load()
     love.graphics.set3D(false)
     love.graphics.setScreen('bottom')
     love.graphics.setBackgroundColor(0,0,0) --Black background
     font = love.graphics.newFont("font.ttf",15)
     love.graphics.setFont("font.ttf")
end

function love.draw()
     love.graphics.setColor(255,255,255) --White text
     love.graphics.print('Hello World!',20,20)
end
 

GalladeGuy

Cool and Epic
Member
Joined
Oct 28, 2015
Messages
2,686
Trophies
1
XP
3,115
Country
United States
I have another question. (Im sorry)
How could i make my main.lua load another lua file?
For example
Code:
function love.keypressed(key)
if key == "select" then
        I want to load another lua file here

How could i do this?
Code:
function love.keypressed(key)
if key == "select" then
        dofile(/3ds/homebrew-name]/code.lua)
end
I think this is how you do it.
 
  • Like
Reactions: Fr0zenIce

TurtleP

Well-Known Member
Member
Joined
Oct 7, 2015
Messages
140
Trophies
0
Age
28
Website
TurtleP.github.io
XP
308
Country
United States
More likely:

function love.keypressed(key)
if key == "select" then
require ("someluafile")​
end​
end

The 'someluafile' should be the path to the .lua file you wish to load. I'm not sure why you'd do this, as it's good practice to require any and all .lua files above love.load in global space.
 

VideahGams

Well-Known Member
OP
Newcomer
Joined
Aug 29, 2015
Messages
91
Trophies
0
Age
26
Location
Glasgow, Scotland
Website
videah.xyz
XP
156
Country
Code:
function love.keypressed(key)
if key == "select" then
        dofile(/3ds/homebrew-name]/code.lua)
end
I think this is how you do it.

Using dofile() is bad practice, you should use require() instead.
Code:
function love.keypressed(key)
   if key == "select" then
     require('path.to.lua.file') -- Don't add .lua at the end, use dots instead of slashes
   end
end

The path is relative from the game folder, so if you wanted to require game/stuff/character.lua, it would be require('stuff.character')

As TurtleP said above though, you probably just want to require stuff at the top of the script rather than in a function.
 
Last edited by VideahGams,

XavyrrVaati

Hobbyist programmer?
Member
Joined
Feb 23, 2014
Messages
385
Trophies
0
XP
478
Country
United States
Another question! (I really am sorry if im bothering anyone :P)
Lets say i have a character on the screen, this character has a position of X:25
and Y:25, how can i make it so the character cant go below the 25 X point? Kind of like it can go above 25 but not below.
(Sorry if im not making any sense)
In the logic section (I believe that's the love.update?)
You could do this several ways, I like to do it like this:
Code:
if (player.x + player.xspeed < 25) {
     player.xspeed = 0;
} //sorry if this isn't lua, I think in C++ lol
//What this does is it checks to see if the player's movement would cause the
//player's x value to be below 25, and if it would, it makes the player's speed 0.
//This probably need a little work to be a tiny bit better, but it should work, and
//this how most collision detection would work. (I'm bad at coding so don't actually
// take my word for anything though hhahaha....)

EDIT: This is lua style (I think):
Code:
if player.x + player.hsp < 25 then --player.hsp is whatever you use for your player's horizontal movement!
     player.hsp = 0
end
 
Last edited by XavyrrVaati,
  • Like
Reactions: Fr0zenIce

VideahGams

Well-Known Member
OP
Newcomer
Joined
Aug 29, 2015
Messages
91
Trophies
0
Age
26
Location
Glasgow, Scotland
Website
videah.xyz
XP
156
Country
Just curious, why is that?

dofile() loads a file and executes it, require() keeps a track of what you've already loaded so you don't accidentally load the same code twice.
require() is also the Lua standard way of loading modules, at least for Lua 5.1 onwards (LövePotion uses 5.1)

Another question! (I really am sorry if im bothering anyone :P)
Lets say i have a character on the screen, this character has a position of X:25
and Y:25, how can i make it so the character cant go below the 25 X point? Kind of like it can go above 25 but not below.
(Sorry if im not making any sense)

The absolute simplest way of doing that is something like this:
Code:
if character.x < 25 then
   character.x = 25
end
 
  • Like
Reactions: Fr0zenIce

XavyrrVaati

Hobbyist programmer?
Member
Joined
Feb 23, 2014
Messages
385
Trophies
0
XP
478
Country
United States
I've absolutely rekt my brain on this, but I'm trying to get a finite state machine to work, my code looks like this:
main.lua
Code:
gameStates = {
  intro = {load, draw, update},
  select = {load, draw, update}
}
gameState = 1
require('intro')
require('select')

function love.load()
  --blahblah
  gameStates[gameState]:load()
end

function love.draw()
  --blahblah
  gameStates[gameState]:draw()
end

function love.update(dt)
  --blahblah
  gameStates[gameState]:update(dt)
end
intro.lua
Code:
function gameStates.intro.load()
  --blahblah more code
end
function gameStates.intro.draw()
  --blahblah more code
end
function gameStates.intro.update(dt)
  --blahblah more code
end
When it gets to
Code:
gameStates[gameState]:load()
I get an error saying "Attempt to index field '?' (a nil value)"
It it how I'm calling the function? I've tried other ways but it throws the same error.
 
Last edited by XavyrrVaati,

VideahGams

Well-Known Member
OP
Newcomer
Joined
Aug 29, 2015
Messages
91
Trophies
0
Age
26
Location
Glasgow, Scotland
Website
videah.xyz
XP
156
Country
I've absolutely rekt my brain on this, but I'm trying to get a finite state machine to work, my code looks like this:
main.lua
Code:
gameStates = {
  intro = {load, draw, update},
  select = {load, draw, update}
}
gameState = 1
require('intro')
require('select')

function love.load()
  --blahblah
  gameStates[gameState]:load()
end

function love.draw()
  --blahblah
  gameStates[gameState]:draw()
end

function love.update(dt)
  --blahblah
  gameStates[gameState]:update(dt)
end
intro.lua
Code:
function gameStates.intro.load()
  --blahblah more code
end
function gameStates.intro.draw()
  --blahblah more code
end
function gameStates.intro.update(dt)
  --blahblah more code
end
When it gets to
Code:
gameStates[gameState]:load()
I get an error saying "Attempt to index field '?' (a nil value)"
It it how I'm calling the function? I've tried other ways but it throws the same error.

A couple of things are wrong with this.

Code:
function love.update(dt)
  --blahblah
  gameStates[gameState]:update(dt)
end

Calling a table function with a colon, puts the table (aka self) as the first argument.
So technically, it's passing itself as dt, and the actual dt is the second argument.

It's equivalent to:

Code:
gameStates[gameState].update(gameStates, dt)

The second problem is you have a table indexed with strings instead of numbers, so gameStates[1] will return nil.
Instead you should use the string index like so:
Code:
gameStates['intro']
 
  • Like
Reactions: XavyrrVaati

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • 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.
  • BakerMan @ BakerMan:
    imagine not having hands, cringe
    +1
  • AncientBoi @ AncientBoi:
    ESPECIALLY for things I do to myself :sad:.. :tpi::rofl2: Or others :shy::blush::evil:
    +1
  • The Real Jdbye @ The Real Jdbye:
    @SylverReZ if you could find a v5 DS ML you would have the best of both worlds since the v5 units had the same backlight brightness levels as the DS Lite unlockable with flashme
  • The Real Jdbye @ The Real Jdbye:
    but that's a long shot
  • The Real Jdbye @ The Real Jdbye:
    i think only the red mario kart edition phat was v5
  • BigOnYa @ BigOnYa:
    A woman with no arms and no legs was sitting on a beach. A man comes along and the woman says, "I've never been hugged before." So the man feels bad and hugs her. She says "Well i've also never been kissed before." So he gives her a kiss on the cheek. She says "Well I've also never been fucked before." So the man picks her up, and throws her in the ocean and says "Now you're fucked."
    +1
  • BakerMan @ BakerMan:
    lmao
  • BakerMan @ BakerMan:
    anyways, we need to re-normalize physical media

    if i didn't want my games to be permanent, then i'd rent them
    +1
  • BigOnYa @ BigOnYa:
    Agreed, that why I try to buy all my games on disc, Xbox anyways. Switch games (which I pirate tbh) don't matter much, I stay offline 24/7 anyways.
  • AncientBoi @ AncientBoi:
    I don't pirate them, I Use Them :mellow:. Like I do @BigOnYa 's couch :tpi::evil::rofl2:
    +1
  • cearp @ cearp:
    @BakerMan - you can still "own" digital media, arguably easier and better than physical since you can make copies and backups, as much as you like.

    The issue is DRM
  • cearp @ cearp:
    You can buy drm free games / music / ebooks, and if you keep backups of your data (like documents and family photos etc), then you shouldn't lose the game. but with a disk, your toddler could put it in the toaster and there goes your $60

    :rofl2:
  • cearp @ cearp:
    still, I agree physical media is nice to have. just pointing out the issue is drm
    cearp @ cearp: still, I agree physical media is nice to have. just pointing out the issue is drm