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.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Music not working & cannot place squares

Post by Davidobot »

Petunien wrote:
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:
So you figured it out the code? What about the "OBEY"
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
Yousar
Prole
Posts: 12
Joined: Thu Mar 29, 2012 12:03 am

Re: Music not working & cannot place squares

Post by Yousar »

What I was intending for this script to do was place a small block, not draw a square from one side of LOVE to the other.
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 »

Then change the parameters... ^^

Code: Select all

love.graphics.rectangle("line", v[1], v[2], 10, 10)
Please read: https://love2d.org/wiki/love.graphics.rectangle
This explains the arrangement of the parameters in a rectangle.
"Docendo discimus" - Lucius Annaeus Seneca
Yousar
Prole
Posts: 12
Joined: Thu Mar 29, 2012 12:03 am

Re: Music not working & cannot place squares

Post by Yousar »

Your making me want to cry.
I already explained I know nothing whatsoever of scripting and I am just starting out.
By just shoving all this in my face, I can't learn anything.
I don't know what parameters are, how I can get a block to be placed where I click.
Nobody ever explained anything to me.
I don't have the LUA manual right next to me.
I am self teaching myself.
I just wish somebody would explain things bit by bit.

EDIT:
Let me just explain what I wanted the script to do in the first place, the thing that nobody taught me.
All I wanted was for the script to place a small square where I clicked.
I mean, about ten by ten pixels, by small square.
I didn't want it to start at the edge of the screen, or anything like that.
All I really was aiming for is placing a block where I click, like in Minecraft.
I know I sound really demanding, but all I wanted was a fix, and an explanation as to why my script wasn't working. Then I was hoping someone would explain the script, and I could learn from there.
Perhaps come back here later because I have another problem, and so on.
I am sure atleast a few people started like this...
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Music not working & cannot place squares

Post by Davidobot »

Yousar wrote:Your making me want to cry.
I already explained I know nothing whatsoever of scripting and I am just starting out.
By just shoving all this in my face, I can't learn anything.
I don't know what parameters are, how I can get a block to be placed where I click.
Nobody ever explained anything to me.
I don't have the LUA manual right next to me.
I am self teaching myself.
I just wish somebody would explain things bit by bit.

EDIT:
Let me just explain what I wanted the script to do in the first place, the thing that nobody taught me.
All I wanted was for the script to place a small square where I clicked.
I mean, about ten by ten pixels, by small square.
I didn't want it to start at the edge of the screen, or anything like that.
All I really was aiming for is placing a block where I click, like in Minecraft.
I know I sound really demanding, but all I wanted was a fix, and an explanation as to why my script wasn't working. Then I was hoping someone would explain the script, and I could learn from there.
Perhaps come back here later because I have another problem, and so on.
I am sure atleast a few people started like this...
Ok, then let me explain some bits of your code:

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" --This means you can use the functions in music.lua in your file

function love.load()
   hamster = love.graphics.newImage("guy.png") --Assigns an image to a variable
   x = 50 -- Assigns X
   y = 50 -- Assigns Y
   speed = 100 --Assigns the speed the object is going at
   love.music()--This calls the functions defined imusic.lua
end

function love.update(dt)
   if love.keyboard.isDown("right") then --Checks if the correct keys are pressed and does the correspoding function
      x = x + (speed * dt)
   elseif love.keyboard.isDown("left") then --Checks if the correct keys are pressed and does the correspoding function
      x = x - (speed * dt)
   end

   if love.keyboard.isDown("down") then --Checks if the correct keys are pressed and does the correspoding function
      y = y + (speed * dt)
   elseif love.keyboard.isDown("up") then --Checks if the correct keys are pressed and does the correspoding function
      y = y - (speed * dt)
   end
end

function love.draw()
   love.graphics.draw(hamster, x, y) --Draws the variable that we have assigned the image to on the x and y axis
end

function love.mousepressed(x, y, button) --Checks if the correct keys are pressed and does the correspoding function
    if button == "1" then
   love.graphics.rectangle("line", 10, 10, x, y) --Draws a rectange , but not filled, just the outline. 10 defines the size. X and Y is where the rectangle is printed.
   end
end

Code: Select all

function love.music() --This makes a new function that you can call up
music = love.audio.newSource("hurricane.mp3") -- if "static" is omitted, LOVE will stream the file from disk, good for longer music tracks. This means that it won't create a copy of the file but it will "play" directly from the hard drive
love.audio.setVolume(1.0) -- This sets the volume
love.audio.play(music) -- This actually plays the music.
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
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Music not working & cannot place squares

Post by Robin »

Yousar wrote:I already explained I know nothing whatsoever of scripting and I am just starting out.
By just shoving all this in my face, I can't learn anything.
I think that means you need to go back a bit. Have you tried playing with Lua's interactive interpreter? Have you checked out some tutorials?

The thing is, you need to learn some basics about programming, otherwise nothing we can say to you will help you. Even if we write the solution for you, the next time you will still need our help.

If you'd like some information about where to find a good tutorial, or how you can start Lua's interactive interpreter, we can help you with that.
Help us help you: attach a .love.
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 »

Yousar wrote:Your making me want to cry.
Sorry.

Let me try to explain what I meant with parameters. By the way, I failed. They are named "arguments".
Arguments are informations that the programm needs to draw, with these you can set the size, start points etc. of the rectangle.

love.graphics.rectangle("line", 0, 0, 10, 10)

1) Command to draw a rectangle.

2) The draw mode (line or fill -> outlined or filled)

3) The X and Y coordinates, where the programm starts to draw the rectangle (the left upper corner of the form).
See this image, it helps to understand:

https://love2d.org/wiki/File:lovecoordsystem.png

4) The width and height of the rectangle, those values start at the X/Y coordinates you set before.

But as Robin said, I recommend you to learn some basics about Lua. :)
"Docendo discimus" - Lucius Annaeus Seneca
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Music not working & cannot place squares

Post by Robin »

Petunien wrote:I recommend you to learn some basics about Lua. :)
And basic programming, that's the most important stuff. Once you know the basics, learning a new language gets easier.
Help us help you: attach a .love.
Yousar
Prole
Posts: 12
Joined: Thu Mar 29, 2012 12:03 am

Re: Music not working & cannot place squares

Post by Yousar »

Ok, thanks for explaining.
Can you please point me to some LUA tutorials?
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Music not working & cannot place squares

Post by Jasoco »

Google for "Lua". All results will help you out.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 4 guests