My two cents here.
In my opinion, the problem is that you call that function inside the love.draw. You should not, since the love.draw. function is called by the main game loop a lot of times every second, so it's normal that is "spams" numbers like this. So, you should select a random question in the love.load function using that function and then, after a specific event happens (for example, the user enters the right question) you lode another question.
Another little advice, it's very important (in not fundamental) to be quite fluent in Lua to programme in Love2D. But, apart from that, I suggest you to implement the game in a command line environment in pure Lua. Then, when it's ok, you start to implement the GUI over that script in Love2D. At least, that's what I do.
Good luck!
[SOLVED] Trivia Game Engine
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- msilvestro
- Prole
- Posts: 29
- Joined: Tue Feb 25, 2014 11:15 pm
- Location: Italy
- Contact:
Re: Trivia Game Engine
It looks like you are calling that function in either update or draw, which happens every frame. You need to only call the function after some condition is met and then set a flag so it isn't called again.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
Re: Trivia Game Engine
Thanks for the tip! I placed the function in [wiki]love.load[/wiki] and it looks like I can go through that since delta time is really fast. Its being called 3 times but it looks fine. Thanks for the tip too!msilvestro wrote:My two cents here.
In my opinion, the problem is that you call that function inside the love.draw. You should not, since the love.draw. function is called by the main game loop a lot of times every second, so it's normal that is "spams" numbers like this. So, you should select a random question in the love.load function using that function and then, after a specific event happens (for example, the user enters the right question) you lode another question.
Another little advice, it's very important (in not fundamental) to be quite fluent in Lua to programme in Love2D. But, apart from that, I suggest you to implement the game in a command line environment in pure Lua. Then, when it's ok, you start to implement the GUI over that script in Love2D. At least, that's what I do.
Good luck!
Thanks for the help! It is a bit flawed but works as it should.Karai17 wrote:It looks like you are calling that function in either update or draw, which happens every frame. You need to only call the function after some condition is met and then set a flag so it isn't called again.
[EDIT]
I know that [wiki]love.graphics[/wiki] should be called in [wiki]love.draw[/wiki] right? Would someone help me make a workaround to solve my problem? I want to run some draw code in [wiki]love.load[/wiki] since thats the only way it works. Thanks!
Re: Trivia Game Engine
You need to access the questions table only once and store the results somewhere that you can access every frame. When a question is answered you need to access the questions table again, rinse and repeat
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
Re: Trivia Game Engine
Sounds a bit too complicated for me as a rookie in Lua. Can you give example code to clear this out a bit? Sorry...
Re: Trivia Game Engine
Code: Select all
function love.load()
questions = {
{ text="Question 1", answer="Answer" },
{ text="Question 2", answer="Answer" },
{ text="Question 3", answer="Answer" },
{ text="Question 4", answer="Answer" },
{ text="Question 5", answer="Answer" }
}
current_question = false
end
function love.update(dt)
if not current_question then
current_question = love.math.random(1, #questions)
end
end
function love.draw()
if current_question then
love.graphics.print(current_question.text, 50, 50)
end
end
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
Re: Trivia Game Engine
Sorry for letting you spoonfeed me, but it returns an error.
attempt to index global 'current_question' (a number value)
I'm very desprate and this is due tomorrow.
attempt to index global 'current_question' (a number value)
I'm very desprate and this is due tomorrow.
Re: Trivia Game Engine
In the random number part, it should be questions[love.math.random(1, #questions)]
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
Re: Trivia Game Engine
How do I say this... Thanks alot? is that it? Its not enough but still, thanks! Its finally solved.
Re: [SOLVED] Trivia Game Engine
<3
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests