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.
Music not working & cannot place squares
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Music not working & cannot place squares
- Attachments
-
- FG.zip
- First game...
- (5.23 MiB) Downloaded 315 times
Re: Music not working & cannot place squares
First of don't upload a .zip upload a .love viewtopic.php?f=4&t=451Yousar 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.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
Re: Music not working & cannot place squares
Well first here is the music.lua: (Both edited)
And here is the main.lua:
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
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
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
Re: Music not working & cannot place squares
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?
However, I still cannot place blocks, which slightly confuses me.
Do you know why?
Re: Music not working & cannot place squares
I have tried altering the code but I also couldn't place blocks. It maybe you should talk to a more expirienced dev.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?
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
Re: Music not working & cannot place squares
Thanks for trying, +1 karma.
Re: Music not working & cannot place squares
It doesn't work because you are calling love.graphics.draw from mousepressed.
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.
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
Re: Music not working & cannot place squares
I have no idea what you just wrote...
But thanks anyway.
But thanks anyway.
Re: Music not working & cannot place squares
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.Yousar wrote:I have no idea what you just wrote...
But thanks anyway.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
Re: Music not working & cannot place squares
What method are you thinking of?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.
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
"Docendo discimus" - Lucius Annaeus Seneca
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 8 guests