The lpr is autogenerated, but to facilitate debugging with console in windows I wanted to allow the app to be CONSOLE when my debug compiler directive is turned on. I guess at some point this will autogenerate maybe when I save from castle game editor and I will lose this. What is the correct way to do this?
Iâm afraid thatâs the only way to do this I know.
Indeed, regenerating the project from Castle Editor will overwrite these changes. This wonât happen accidentally though, you need to explicitly press Code â Regenerate Project.
So to avoid losing the custom code in autogenerated files I just use a version control system (GIT) to track changes, and when I see that something had changed in an undesirable way, I can simply revert the lines:
I have never used âRegenerate Projectâ, so wonât. I most use the editor to figure things out, then code them so they donât appear there anymore. So my editor scene is empty except for screen controls. Sounds like just saving those edits are safe. I tried using windowâs allocconsole as I have in the past for being able to turn on the console on the fly⌠but now it works unreliably and gives me a console that is broken half the time and writelns will fail. Debugging debug console behavior is not my idea of fun!
Indeed, thatâs one way to use Castle Editor - I also personally prefer to instantiate most of the game elements from the code
but now it works unreliably and gives me a console that is broken half the time and writelns will fail. Debugging debug console behavior is not my idea of fun!
Note, that WriteLn is technically not a good way to send logging information. Its behavior depends on the platform (and on specific project settings), and therefore itâs better to use a cross-platform solution: CastleLog. It works on all target platforms CGE supports and smartly detects if {$apptype console} (in this case sends logs to console) or {$apptype gui} (in this case sends log to a log filein AppData folder. To use it just:
It has several more useful features. One thing youâll need to do is to InitializeLog somewhere as early as possible, most likely in initialization section of your program. If you generate a project through Castle Editor it will be there automatically in castleautogenerated.pas.
So in practice it is OK to just refrain from doing the above, or remember to revert the LPR / DPR after regenerating as Eugene shows.
I know itâs not optimal â in the long run I donât want you to worry that âsomeday, this regeneration will be more automaticâ. (Though I donât have plan to change it now, but something may make it necessary in the future.)
Most things can (and should) be placed outside of LPR / DPR actually, to support also non-desktop platforms (like Android, iOS, WebAssembly). But the above $apptype I think work only in LPR / DPR? You can try â maybe putting it in any unit (like gameinitialize.pas) will work too?
If you need CONSOLE for Writeln, then better answer (again repeating Eugene ) is to make a habit of using CGE WritelnLog / WritelnWarning, see Logging | Manual | Castle Game Engine . This will work on all platforms, e.g. on Android it will write to Android facility. And if you run from editor, it will show in editor output. On Windows GUI, it will by default go to file, but (if you know you have stduot available â this happens if you run from console, like Cygwin) you can set CASTLE_LOG environment variable to stdout to force it to go to stdout.
P.S. I recommend to put it inside {$ifdef MSWINDOWS}...{$endif} . This is Windows-specific, FPC will warn that itâs ignored on other platforms.