Code (text) editor embedded in a game?


I’m looking for a way to edit some LUA scripts inside my game. I hoped to find a java-based, embeddable text editor or something like that. I would like it to have syntax highlighting and autocomplete. And I’m 100% sure I’m not the first person to need this kind of functionality in his game. But I cannot find anything, either jme3 based or external. How do you approach this, when you need the user to write anything in a game?

Any help much appreciated.

I don’t think there’s a text editor library ready to be embedded directly in jME as the text formatting may change from GUI to GUI. You may try to find a syntax highlight library and implement the text editor yourself or rely on a JavaFX external window, which will make more probable to find open source components for what you need.

Yep, Swing painted onto a texture or JavaFX painted onto a texture… those are probably the best bets.

1 Like

Swing painted onto a texture sounds great, I have had no idea there is such a possibility. Can you point me in the right direction as of where to start?

Off the top of my head…
create a bufffered image
create a Graphics object from that
paint the Swing component to the graphics object with paint()
copy the contents of the buffered image to a JME texture
repeat once a frame or whatever.

I don’t know if there are any ready examples but others have definitely done it.

The question is if that’s a good idea though. Does your game require coding?
If not why not let the users use professional lua ide’s or at least their atom/vscode/notepad++ and the game just supports hot reloading (watch the file timestamps). Additionally these full blown editors could communicate with the game to enable debugging of some sort.

Otherwise you tend to reinvent the wheel at the cost of having a mediocre editor

I fully agree with the idea of allowing users to write code outside of the game and I think that it is a worthy investment even if a game requires the user to write code (maybe especially then). However, I also think a basic editor right into the game isn’t a bad thing to have.

When I still played Minecraft with the computercraft mod I used to basically write everything using an external editor because the basic editor available is shitty. However, I lost count at how many times being able to quickly edit something made my life a 1000 times easier.

Luckily an in game editor in that scenario doesn’t need to be that complicated. Just being able to view at what line I’m at was good enough for pretty much all those times (so, no code highlighting and no auto complete)

There is one thing to consider though: how likely is it that your target audience has 2 or more monitors? Based on that answer you may need to think about ways to make people comfortable switching to another program (thus not being able to see what is going on in the game) or make the in game editor good enough to where people feel they can safely use it without missing out on too many features they would otherwise have.