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,105
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
  • No one is chatting at the moment.
    AncientBoi @ AncientBoi: :rofl2: +1