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
Create a message box without using libraries by others
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Create a message box without using libraries by others
What you need is an array of messages (table with string entries) and a counter that tells you which of the messages to show.
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.
Code: Select all
messages = {'First', 'Second', 'And so on'}
counter = 1
Code: Select all
showBox(messages[counter])
When the counter is increased you have to check if you are at the end of the messages:
Code: Select all
if counter > #messages then
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.
Check out my blog on gamedev
Re: Create a message box without using libraries by others
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.
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
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
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
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
I can't seem to clear it out after showing the message lol
Re: Create a message box without using libraries by others
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.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
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
Can you please upload a .love-file? The solution to this problem depends on how you implemented everything.
Check out my blog on gamedev
Re: Create a message box without using libraries by others
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
Lua is such a nice thing
Check it out
- Attachments
-
- messagebox2.love
- Printing letters with delay
- (629 Bytes) Downloaded 231 times
Last edited by RedHot on Thu Jul 18, 2013 12:47 pm, edited 1 time in total.
Re: Create a message box without using libraries by others
Hi everyone! Thank you for the help, I finally got it!
Here's a demo if you want to see it in my game 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!
Here's a demo if you want to see it in my game 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!
Who is online
Users browsing this forum: Bing [Bot] and 2 guests