[Solved] Help with buttons
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 5
- Joined: Sun Oct 05, 2014 5:51 am
[Solved] Help with buttons
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
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 302 times
Last edited by billythecodingkid on Sun Oct 05, 2014 10:24 am, edited 2 times in total.
Re: Help with buttons
Here's a solution:
make a gamestate variable.
heres an example:
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
-
- Prole
- Posts: 5
- Joined: Sun Oct 05, 2014 5:51 am
Re: Help with buttons
I do have a gamestate variable, yet it does not fix the problem. I think it might be how I coded it -- I think.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
Re: Help with buttons
-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.
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.
Re: Help with 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.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.
Re: Help with buttons
Add an id to each button. Then you could doAlexCalv 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.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.
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
Re: Help with buttons
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!
-
- Prole
- Posts: 5
- Joined: Sun Oct 05, 2014 5:51 am
Re: Help with buttons
Hmm... maybe try forAlexCalv 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.
Code: Select all
for i,v in ipairs(t) do
table.remove(t, i)
end
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.
Re: Help with buttons
No problem.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!
edit: billythecodingkid, this could fix your button problem. Try and implement what I said.
-
- Prole
- Posts: 5
- Joined: Sun Oct 05, 2014 5:51 am
Re: Help with buttons
I implemented
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
Code: Select all
for i,v in ipairs(t) do
table.remove(t, i)
end
EDIT: Still happens with your way. I might as well redo the whole code used for the buttons maybe that will work
Last edited by billythecodingkid on Sun Oct 05, 2014 8:15 am, edited 1 time in total.
Who is online
Users browsing this forum: Amazon [Bot], Google [Bot] and 6 guests