Jump to content

Any way to make message boxes?


Kraxie
 Share

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

Windows 7 | Intel Core i7-4790K | 16 GB RAM | Nvidia GTX 980

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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 :/

Windows 7 | Intel Core i7-4790K | 16 GB RAM | Nvidia GTX 980

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Windows 7 | Intel Core i7-4790K | 16 GB RAM | Nvidia GTX 980

Link to comment
Share on other sites

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.

  • Upvote 1
Link to comment
Share on other sites

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...

Windows 7 | Intel Core i7-4790K | 16 GB RAM | Nvidia GTX 980

Link to comment
Share on other sites

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.

  • Upvote 1
Link to comment
Share on other sites

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.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

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

Windows 7 | Intel Core i7-4790K | 16 GB RAM | Nvidia GTX 980

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...