Jump to content
Kraxie

Any way to make message boxes?

Recommended Posts

Hello!

 

I wanted to make some sort of message box to pop up for the player if for example an error occurred and I wanted it to show a popup box instead of just logging it into a console.

 

Is this possible?

If not, is there a module or something to add the ability to do this?

 

Thanks, KraXarN

Share this post


Link to post

You can either code it yourself using context commands

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/

 

or use existing code. Either a GUI available for purchase like FlowGUI

http://www.leadwerks.com/werkspace/topic/11262-flowgui-for-leadwerks/

 

or maybe this would be simpler

http://www.leadwerks.com/werkspace/topic/12374-multiple-text-gui/

Share this post


Link to post

You can either code it yourself using context commands

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/

 

or use existing code. Either a GUI available for purchase like FlowGUI

http://www.leadwerks.com/werkspace/topic/11262-flowgui-for-leadwerks/

 

or maybe this would be simpler

http://www.leadwerks.com/werkspace/topic/12374-multiple-text-gui/

 

Hm, so basically I create a new window and then render text inside it?

 

error("This pops up this text")

 

That just results in a script error :/

 

Do you want the pop up box to stop the game? If so this is what you want. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/debug/debugerror-r752

 

If you want it in game then you may have to choose it yourself.

 

That just stops the game and logs the error to the console with no popup message :/

Share this post


Link to post

Hm, so basically I create a new window and then render text inside it?

The simplest way is to draw a filled rectangle using this command

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextdrawrect-r724

and then draw text over that with this command (with a different color)

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextdrawtext-r731

 

If you want to get fancy you can replace the rectangle with an image and draw it with the DrawImage command, then do the text on top of that

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextdrawimage-r721

 

Check out the sample code on how to use the commands.

Share this post


Link to post

The simplest way is to draw a filled rectangle using this command

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextdrawrect-r724

and then draw text over that with this command (with a different color)

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextdrawtext-r731

 

If you want to get fancy you can replace the rectangle with an image and draw it with the DrawImage command, then do the text on top of that

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextdrawimage-r721

 

Check out the sample code on how to use the commands.

 

Hm, okay, but I can't seem to create a new window without duplicating my current one... It seems like I need to set the Window:Create() outside of App.lua, but how do I do that and still be able to call it from any other script?

Share this post


Link to post

So you have to think about what you want here. You can have in-game message box or you can have an OS message box. The OS message box would have nothing to do with LE. You'd have to code this in C++ for the platform you are on. On windows just look up Windows MessageBox to see how to do this. For Linux I'm not sure exactly how, but I'm sure they have something.

 

Gamecreator's solution is more in-game. You are just drawing images/rects on screen to simulate a window and drawing text and buttons and such. You are making the message box yourself with LE commands this way.

Share this post


Link to post

So you have to think about what you want here. You can have in-game message box or you can have an OS message box. The OS message box would have nothing to do with LE. You'd have to code this in C++ for the platform you are on. On windows just look up Windows MessageBox to see how to do this. For Linux I'm not sure exactly how, but I'm sure they have something.

 

Gamecreator's solution is more in-game. You are just drawing images/rects on screen to simulate a window and drawing text and buttons and such. You are making the message box yourself with LE commands this way.

 

I want something as close to an OS Box as possible. I only have the Indie Edition, but I'll probably get the Standard Edition next time it goes on sale, so I might just have to wait until then if there is no other way to do it...

Share this post


Link to post

You are now heading for technical territory. First you will need to turn off

Sandbox Lua

in the Leadwerks options menu. Your game will not work in the Leadwerks game player on Steam anymore.

 

Now add this code when you want to make w messagebox appear

 

local ffi = require("ffi")
ffi.cdef[[int MessageBoxA(void *w, const char *txt, const char *cap, int type);]]
self.window:ShowMouse()
ffi.C.MessageBoxA(nil, "Hello world!", "Test", 0)
self.window:HideMouse()

 

Reference: http://luajit.org/ext_ffi.html

 

Beyond this example I can't help as it is beyond my ability as a programmer.

Share this post


Link to post

Also, note that I think that would only work for Windows. If you wanted this on Linux you'd have to research that and probably do some #ifdef in that code.

Share this post


Link to post

I just designed a message box in paint.net and used drawimage to show it when a key is pressed.

It contains instructions for key presses during game.

Share this post


Link to post

You are now heading for technical territory. First you will need to turn off

Sandbox Lua

in the Leadwerks options menu. Your game will not work in the Leadwerks game player on Steam anymore.

 

Now add this code when you want to make w messagebox appear

 

local ffi = require("ffi")
ffi.cdef[[int MessageBoxA(void *w, const char *txt, const char *cap, int type);]]
self.window:ShowMouse()
ffi.C.MessageBoxA(nil, "Hello world!", "Test", 0)
self.window:HideMouse()

 

Reference: http://luajit.org/ext_ffi.html

 

Beyond this example I can't help as it is beyond my ability as a programmer.

 

Exactly what I was looking for! Thanks! laugh.png

 

Also, note that I think that would only work for Windows. If you wanted this on Linux you'd have to research that and probably do some #ifdef in that code.

 

I read on that site somewhere that it sadly was Windows only... I'll see if I can get it working on Linux as well, that would be great.

 

I just designed a message box in paint.net and used drawimage to show it when a key is pressed.

It contains instructions for key presses during game.

 

I'm looking for some sort of OS Info Box, not something in-game tongue.png

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...