Page 1 of 1
Create a message box without using libraries by others
Posted: Wed Jul 17, 2013 10:55 am
by carbajosa
Hello everyone! I wanted to ask if it is possible to create a very simple message boxes?
I am creating an event handler for my game and well, I wanted to implement a message handler. Like for example, a player has stepped on an event block and pressed Z, a message box will appear.
I have also created an example of what I wanted to achieve. Because I wanted to make it in sequence. For example, a message has been shown then you pressed Z, the next message will show until the end of the "array of messages" has been reached and then starts to clears everything. (the array and the printing on the game screen)
The reason of refusing the use of other existing message box libraries like NAVI is because I wanted to learn how to do it on my own. I tried checking the source code of NAVI but it's quite complicated for a simple game that I am creating. I just wanted to make a message show. And when I learned the base of the code then surely, I can enhance and extend its features.
That is all, thank you
Re: Create a message box without using libraries by others
Posted: Wed Jul 17, 2013 11:54 am
by micha
What you need is an array of messages (table with string entries) and a counter that tells you which of the messages to show.
Code: Select all
messages = {'First', 'Second', 'And so on'}
counter = 1
The drawing read the counter and creats a box with the correct message. Something like this:
And each time you press "z" you increase the counter by one.
When the counter is increased you have to check if you are at the end of the messages:
and then remove the stack of messages from the handler.
Then you should also think about what should happen to the game, when a message is displayed? Should the rest of the game stop? Or only parts? Or nothing? Depending on that you have to integrate it into the love.update() and love.draw() accordingly.
Re: Create a message box without using libraries by others
Posted: Wed Jul 17, 2013 6:05 pm
by pacman
Yesterday I just finished my code for little dialog boxes.
Basically I needed single popup above NPC which I could skip with button press.
I made it using player.dialogState. It is nil if there is noone to talk, "inactive" if I'm close enough to someone (then I'm displaying "TALK" icon) and "active" when the dialog magic is happening.
When you talk to NPC it's filling "dialog" array with elements - it can be plain text, image, a lot of options, X/Y position etc.
It also changes dialogState to "active" so you can't do anything else other that skip dialog.
Code: Select all
if currentElement < #dialog then
display another one (...)
else
change dialogState to nil so everything can move again
end
Update and Draw everything only if dialogState is active.
That's the simpliest way I could think off... I guess it's not bad for game with a few "Hello hero!" popups here and there.
But if you really NEED dialogs make it better
Re: Create a message box without using libraries by others
Posted: Thu Jul 18, 2013 3:00 am
by carbajosa
But how about clearing the rectangle that I used? (love.graphics.rectangle)
I can't seem to clear it out after showing the message lol
Re: Create a message box without using libraries by others
Posted: Thu Jul 18, 2013 5:45 am
by micha
carbajosa wrote:But how about clearing the rectangle that I used? (love.graphics.rectangle)
I can't seem to clear it out after showing the message lol
Since the whole graphics are drawn new each frame, there is no 'clearing' but only 'not drawing'. But I guess that is what you mean.
I'd do it this way. With the stuff I wrote in the post above I could do this:
Code: Select all
if counter <= #messages then
showMessage(messages[counter])
end
So if the counter gets larger than the number of messages, then nothing is displayed.
Can you please upload a .love-file? The solution to this problem depends on how you implemented everything.
Re: Create a message box without using libraries by others
Posted: Thu Jul 18, 2013 9:59 am
by RedHot
With very little fiddling I have managed to allow printing letters one by one by a custom delta.
Lua is such a nice thing
Check it out
Re: Create a message box without using libraries by others
Posted: Thu Jul 18, 2013 12:38 pm
by carbajosa
Hi everyone! Thank you for the help, I finally got it!
Here's a demo if you want to see it in my game
- game.love
- Demo
- (54.33 KiB) Downloaded 238 times
Instruction: Step on the event blocks and press "
z". It will run the event if you are facing the right direction.
It's a bit fugly and buggy at the moment but I got the idea so the thing I will do now is to improvise and fix all the existing bugs.
(One notable bugs in it is the message container. If the other event has 2 messages and the other one has only 1 message then it will print out the second message from the other event. Also if you kinda move so fast at the edge of the map while pressing Z, you'll get stucked. sometimes.)
Thank you all!