Music not working & cannot place squares

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Yousar
Prole
Posts: 12
Joined: Thu Mar 29, 2012 12:03 am

Music not working & cannot place squares

Post by Yousar »

The problem is my music isn't working and I have made a script to place squares.
But the script isn't placing the squares and since I am very (very) new to LUA, I have no idea what I'm doing wrong.
Please could you point out what's wrong with the script and that'll make my day.
Attachments
FG.zip
First game...
(5.23 MiB) Downloaded 147 times
User avatar
Davidobot
Party member
Posts: 1213
Joined: Sat Mar 31, 2012 5:18 am
Location: Cambridge, UK
Contact:

Re: Music not working & cannot place squares

Post by Davidobot »

Yousar wrote:The problem is my music isn't working and I have made a script to place squares.
But the script isn't placing the squares and since I am very (very) new to LUA, I have no idea what I'm doing wrong.
Please could you point out what's wrong with the script and that'll make my day.
First of don't upload a .zip upload a .love viewtopic.php?f=4&t=451
My projects: Raycaster, love.js v11.3 port
itch page: link
My website: link
My library: LovelyMoon
User avatar
Davidobot
Party member
Posts: 1213
Joined: Sat Mar 31, 2012 5:18 am
Location: Cambridge, UK
Contact:

Re: Music not working & cannot place squares

Post by Davidobot »

Well first here is the music.lua: (Both edited)

Code: Select all

function love.music()
music = love.audio.newSource("hurricane.mp3") -- if "static" is omitted, LЦVE will stream the file from disk, good for longer music tracks
love.audio.setVolume(1.0)
love.audio.play(music)
end
And here is the main.lua:

Code: Select all

-- Tutorial 1: Hamster Ball
-- Add an image to the game and move it around using 
-- the arrow keys.
-- compatible with lцve 0.6.0 and up
require "music.lua"

function love.load()
   hamster = love.graphics.newImage("guy.png")
   x = 50
   y = 50
   speed = 100
   love.music()
end

function love.update(dt)
   if love.keyboard.isDown("right") then
      x = x + (speed * dt)
   elseif love.keyboard.isDown("left") then
      x = x - (speed * dt)
   end

   if love.keyboard.isDown("down") then
      y = y + (speed * dt)
   elseif love.keyboard.isDown("up") then
      y = y - (speed * dt)
   end
end

function love.draw()
   love.graphics.draw(hamster, x, y)
end

function love.mousepressed(x, y, button)
    if button == "1" then
	love.graphics.rectangle("line", 10, 10, x, y)
	end
end
My projects: Raycaster, love.js v11.3 port
itch page: link
My website: link
My library: LovelyMoon
Yousar
Prole
Posts: 12
Joined: Thu Mar 29, 2012 12:03 am

Re: Music not working & cannot place squares

Post by Yousar »

Thanks Davidobot, I have noticed the mistakes you fixed and I hope I don't make that error again.
However, I still cannot place blocks, which slightly confuses me.
Do you know why?
User avatar
Davidobot
Party member
Posts: 1213
Joined: Sat Mar 31, 2012 5:18 am
Location: Cambridge, UK
Contact:

Re: Music not working & cannot place squares

Post by Davidobot »

Yousar wrote:Thanks Davidobot, I have noticed the mistakes you fixed and I hope I don't make that error again.
However, I still cannot place blocks, which slightly confuses me.
Do you know why?
I have tried altering the code but I also couldn't place blocks. It maybe you should talk to a more expirienced dev.
My projects: Raycaster, love.js v11.3 port
itch page: link
My website: link
My library: LovelyMoon
Yousar
Prole
Posts: 12
Joined: Thu Mar 29, 2012 12:03 am

Re: Music not working & cannot place squares

Post by Yousar »

Thanks for trying, +1 karma.
iemfi
Citizen
Posts: 52
Joined: Fri Mar 30, 2012 11:03 am

Re: Music not working & cannot place squares

Post by iemfi »

It doesn't work because you are calling love.graphics.draw from mousepressed.

Code: Select all

objects={}
objects.rectangles={}
function love.draw()
   for i,v in ipairs(objects.rectangles) do --we loop through every entry in the objects.rectangle table
          love.graphics.rectangle("line", 10, 10, v[1], v[2]) --draw the rectangle (I don't know why want them starting at 10,10).
   end
   love.graphics.draw(hamster, x, y)
end

function love.mousepressed(x, y, button)
    if button == "1" then
	table.insert(objects.rectangles,{x,y}) -- we add the mouse coordinates to the objects.rectangle table
    end
end
This would work but I would suggest learning and using an Object Oriented method instead if you're going to make a more complex game.
Yousar
Prole
Posts: 12
Joined: Thu Mar 29, 2012 12:03 am

Re: Music not working & cannot place squares

Post by Yousar »

I have no idea what you just wrote...
But thanks anyway.
User avatar
Davidobot
Party member
Posts: 1213
Joined: Sat Mar 31, 2012 5:18 am
Location: Cambridge, UK
Contact:

Re: Music not working & cannot place squares

Post by Davidobot »

Yousar wrote:I have no idea what you just wrote...
But thanks anyway.
He wrote that you need to put the draw block thing into the draw function. But I tried it and it still didn't work. :(
My projects: Raycaster, love.js v11.3 port
itch page: link
My website: link
My library: LovelyMoon
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: Music not working & cannot place squares

Post by Petunien »

iemfi wrote: This would work but I would suggest learning and using an Object Oriented method instead if you're going to make a more complex game.
What method are you thinking of?
I also have some troubles getting started.

Edit:
iemfi wrote:

Code: Select all

...
function love.mousepressed(x, y, button)
    if button == "1" then
   table.insert(objects.rectangles,{x,y}) -- we add the mouse coordinates to the objects.rectangle table
    end
end

It should be:

Code: Select all

function love.mousepressed(x, y, button)
    if button == "l" then
    table.insert(objects.rectangles,{x,y}) -- we add the mouse coordinates to the objects.rectangle table
    end
end
A "l" instead of a "1" in the if-statement. :crazy:
"Docendo discimus" - Lucius Annaeus Seneca
Post Reply

Who is online

Users browsing this forum: DrNefario, Google [Bot] and 32 guests