How can I run Raw code from my love2d console?

Viewed 39

Hi I want to make a dev console where when you type anything thats will run. Like if you type in the console:

Player.hp += 20

Then its gonna execute.

1 Answers

When you do in love.update()...

function love.update(dt)                                                           
  world:update(dt) -- this puts the world into motion                      
  -- here we are going to create some keyboard events                      
  -- press the right arrow key to push the ball to the right               
  if love.keyboard.isDown("right") then                                    
    objects.ball.body:applyForce(400, 0)                                           
  -- press the left arrow key to push the ball to the left                         
  elseif love.keyboard.isDown("left") then                                         
    objects.ball.body:applyForce(-400, 0)                                          
  -- press the up arrow key to set the ball in the air                             
  elseif love.keyboard.isDown("up") then                                   
    objects.ball.body:setPosition(650/2, 650/2)                                    
    -- we must set the velocity to zero to prevent a potentially large             
    -- velocity generated by the change in position                        
    objects.ball.body:setLinearVelocity(0, 0)                              
  elseif love.keyboard.isDown("tab") then                                  
    debug.debug()                                                                  
  elseif love.keyboard.isDown("escape") then                               
    love.event.quit()                                                              
  end                                                                      
end

Free from: https://love2d.org/wiki/Tutorial:Physics

Than Tab can be used to modify the paused Game.
Thats only works when main.lua was started from a Terminal.
Else the "lua_debug> " Prompt is not visible.

Try for example...

lua_debug> objects.ball = {}
lua_debug> objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic")
lua_debug> objects.ball.shape = love.physics.newCircleShape(50)
lua_debug> objects.ball.fixture = love.physics.newFixture(objects.ball.body,objects.ball.shape, 1)
lua_debug> objects.ball.fixture:setRestitution(1)
lua_debug> cont

...and the big Ball bounce forever.

Related