[Solved] Help with buttons

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.
billythecodingkid
Prole
Posts: 5
Joined: Sun Oct 05, 2014 5:51 am

[Solved] Help with buttons

Post by billythecodingkid »

So I'm currently trying to make a Pokemon type game were is is basically a infinite fighting game with new enemies piping up after the old one has died. Right know I am trying to make the start menu buttons work properly, I have made it so that it if you click start it starts the game but the buttons won't disappear. Also I need help with my button library so it knows which button is clicked (I have a general idea of what should how it should work but I don't know how to properly do it). If you find any other things I'm doing wrong, could you tell me because Im not really a expert in Lua at the moment.

Ps: Don't mind the Click X and Click Y, its just there to place images in the right place
Attachments
Voxmon.love
The .love of the game
(83.14 KiB) Downloaded 301 times
Last edited by billythecodingkid on Sun Oct 05, 2014 10:24 am, edited 2 times in total.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Help with buttons

Post by Doctory »

Here's a solution:

make a gamestate variable.
heres an example:

Code: Select all

function love.load()
  gamestate = "menu"
  --your code
end

function love.draw()
  if gamestate == "menu"
    --draw the buttons here
    --everything thats supposed to be in the menu
  elseif gamestate == "game" then
    --draw game buttons and everything else game related
end

--love functions
billythecodingkid
Prole
Posts: 5
Joined: Sun Oct 05, 2014 5:51 am

Re: Help with buttons

Post by billythecodingkid »

Doctory wrote:Here's a solution:

make a gamestate variable.
heres an example:

Code: Select all

function love.load()
  gamestate = "menu"
  --your code
end

function love.draw()
  if gamestate == "menu"
    --draw the buttons here
    --everything thats supposed to be in the menu
  elseif gamestate == "game" then
    --draw game buttons and everything else game related
end

--love functions
I do have a gamestate variable, yet it does not fix the problem. I think it might be how I coded it -- I think.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Help with buttons

Post by Doctory »

-snip-

The gamestate variable should be checked in love.draw, not love.load.
EDIT:
Heres a solution I think would be of help:
Add a function that will remove buttons, so when you are in the game state, remove the menu buttons.
User avatar
AlexCalv
Prole
Posts: 49
Joined: Fri Aug 08, 2014 7:12 pm
Contact:

Re: Help with buttons

Post by AlexCalv »

Doctory wrote:-snip-

The gamestate variable should be checked in love.draw, not love.load.
EDIT:
Heres a solution I think would be of help:
Add a function that will remove buttons, so when you are in the game state, remove the menu buttons.
I was having trouble with this type of method of adding buttons earlier as well. How would you write a remove function? When I tried table.remove(buttons, i) it only removed the first button.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Help with buttons

Post by Doctory »

AlexCalv wrote:
Doctory wrote:-snip-

The gamestate variable should be checked in love.draw, not love.load.
EDIT:
Heres a solution I think would be of help:
Add a function that will remove buttons, so when you are in the game state, remove the menu buttons.
I was having trouble with this type of method of adding buttons earlier as well. How would you write a remove function? When I tried table.remove(buttons, i) it only removed the first button.
Add an id to each button. Then you could do

Code: Select all

function removeButton(id)
  for i,k in ipairs(buttons) do
    if k.id == id then
      table.remove(buttons, i)
    end
  end
end
edit: thats just for a specific button btw.
User avatar
AlexCalv
Prole
Posts: 49
Joined: Fri Aug 08, 2014 7:12 pm
Contact:

Re: Help with buttons

Post by AlexCalv »

I don't know how I didn't think of that earlier. I already have ids to the buttons. I really wasn't using my head on this one lmao. Thanks!
billythecodingkid
Prole
Posts: 5
Joined: Sun Oct 05, 2014 5:51 am

Re: Help with buttons

Post by billythecodingkid »

AlexCalv wrote: I was having trouble with this type of method of adding buttons earlier as well. How would you write a remove function? When I tried table.remove(buttons, i) it only removed the first button.
Hmm... maybe try for

Code: Select all

for i,v in ipairs(t) do 
    table.remove(t, i) 
end
and replacing t with the table name

EDIT: Or do what the doctor said, preferable the doctor
Last edited by billythecodingkid on Sun Oct 05, 2014 8:05 am, edited 1 time in total.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Help with buttons

Post by Doctory »

AlexCalv wrote:I don't know how I didn't think of that earlier. I already have ids to the buttons. I really wasn't using my head on this one lmao. Thanks!
No problem.
edit: billythecodingkid, this could fix your button problem. Try and implement what I said.
billythecodingkid
Prole
Posts: 5
Joined: Sun Oct 05, 2014 5:51 am

Re: Help with buttons

Post by billythecodingkid »

I implemented

Code: Select all

for i,v in ipairs(t) do 
    table.remove(t, i) 
end
in love.update() and it does remove them but it does it with a second delay so I'm going to try what you said doc

EDIT: Still happens with your way. I might as well redo the whole code used for the buttons maybe that will work :death:
Last edited by billythecodingkid on Sun Oct 05, 2014 8:15 am, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests