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

Discussion in '3DS - Homebrew Development and Emulators' started by VideahGams, Sep 17, 2015.

  1. Substance12

    Substance12 GBAtemp Advanced Fan

    Member
    4
    Aug 2, 2015
    Argentina
    Preferences :P
     
  2. XavyrrVaati

    XavyrrVaati Hobbyist programmer?

    Member
    4
    Feb 23, 2014
    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, Jan 18, 2016
    VideahGams likes this.
  3. Substance12

    Substance12 GBAtemp Advanced Fan

    Member
    4
    Aug 2, 2015
    Argentina
    Yeah... turn off the 3D slider or your eyes will fall off :P
     
    XavyrrVaati likes this.
  4. Tobold

    Tobold Newbie

    Newcomer
    1
    Jan 13, 2016
    Gambia, The
    Seperators in what way? In your example, would the full path be:
    Code:
    /3ds/lovepotion/game/stuff/stuff/code.lua
    ?
     
  5. Tobold

    Tobold Newbie

    Newcomer
    1
    Jan 13, 2016
    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.
     
  6. Substance12

    Substance12 GBAtemp Advanced Fan

    Member
    4
    Aug 2, 2015
    Argentina
    No. The syntax for require is using . as separators, not /, and not writing the file extension.
     
  7. VideahGams
    OP

    VideahGams Advanced Member

    Newcomer
    2
    Aug 29, 2015
    Glasgow, Scotland
    love.system.getOS() returns '3ds' in LövePotion
     
  8. haazet

    haazet Advanced Member

    Newcomer
    2
    Dec 15, 2015
    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
     
  9. Substance12

    Substance12 GBAtemp Advanced Fan

    Member
    4
    Aug 2, 2015
    Argentina
    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
     
  10. Substance12

    Substance12 GBAtemp Advanced Fan

    Member
    4
    Aug 2, 2015
    Argentina
    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
     
  11. Substance12

    Substance12 GBAtemp Advanced Fan

    Member
    4
    Aug 2, 2015
    Argentina
    Replace "love.graphics.setFont("font.ttf")" with "love.graphics.setFont(font)"
     
    Fr0zenIce likes this.
  12. GalladeGuy

    GalladeGuy Cool and Epic

    Member
    11
    Oct 28, 2015
    United States
    Code:
    function love.keypressed(key)
    if key == "select" then
            dofile(/3ds/homebrew-name]/code.lua)
    end
    
    I think this is how you do it.
     
    Fr0zenIce likes this.
  13. TurtleP

    TurtleP GBAtemp Regular

    Member
    3
    Oct 7, 2015
    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.
     
  14. VideahGams
    OP

    VideahGams Advanced Member

    Newcomer
    2
    Aug 29, 2015
    Glasgow, Scotland
    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, Jan 28, 2016
    Fr0zenIce and GalladeGuy like this.
  15. Tobold

    Tobold Newbie

    Newcomer
    1
    Jan 13, 2016
    Gambia, The
    Just curious, why is that?
     
  16. XavyrrVaati

    XavyrrVaati Hobbyist programmer?

    Member
    4
    Feb 23, 2014
    United States
    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, Jan 31, 2016
    Fr0zenIce likes this.
  17. VideahGams
    OP

    VideahGams Advanced Member

    Newcomer
    2
    Aug 29, 2015
    Glasgow, Scotland
    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)

    The absolute simplest way of doing that is something like this:
    Code:
    if character.x < 25 then
       character.x = 25
    end
    
     
    Fr0zenIce likes this.
  18. XavyrrVaati

    XavyrrVaati Hobbyist programmer?

    Member
    4
    Feb 23, 2014
    United States
    That works well, but I've seen that cause rubberbanding. Might've done it wrong too. :v /shrug
     
  19. XavyrrVaati

    XavyrrVaati Hobbyist programmer?

    Member
    4
    Feb 23, 2014
    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, Mar 13, 2016
  20. VideahGams
    OP

    VideahGams Advanced Member

    Newcomer
    2
    Aug 29, 2015
    Glasgow, Scotland
    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']
    
     
    XavyrrVaati likes this.
Quick Reply
Draft saved Draft deleted
Loading...