Forum > Beginners
Using the Castle Game Engine Without Any Prior Coding Experience
JPF12141999:
Hi everyone,
I didn't specify I was autsitic and took directions very literally/read the words exactly as they were, which might have been part of the problem,
but I did specify I was approaching the usage of a free game engine, called "Castle Game Engine" that can be downloaded by Googling "Castle Game Engine Download", from the perspective of an absolute beginner that doesn't know the ins and outs of the particular language's details, but knows in general that "var" means variable, or "begin" and "end" begin and end a specific block of code, and they need to happen for the code to work in multi line blocks.
On another thread in the Lazarus forums, but not the beginner's section, which is probably also part of the problem, because they assume you aren't an absolute beginner but know how to figure things out by yourself by reading the manual,
I was told to read the manual for help, rather than actually being given the help directly.
This is fine given that it's not aimed at beginners but rather people who know Pascal well already, but the responses were very beginner unfriendly like "this thread is pure comedy gold" or "don't change the code then complain when it doesn't work", even though I would point out using examples how the changes were done to the best of my ability by following what the example projects' code suggests I should do.
Does anyone with professional insider knowledge/experience with the Castle Game Engine want to help me, as it is clear that they just want to keep referring me to the manual/telling me to RTFM rather than actually properly walking me through it or spelling anything out themself?
In particular, I need help with this piece of code, about drawing a raycast from a player transform; I need the player's coordinates the way they are to control the location precisely of the ray being drawn to the ground, but again cause they assumed I had enough insider knowledge they never bothered to show me how directly on the other thread, but kept telling me to teach everything to myself:
Original example's code for gamemymesh.pas, note it compiles fine exactly as it is:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{ Copyright 2023-2023 Michalis Kamburelis. This file is part of "Castle Game Engine". "Castle Game Engine" is free software; see the file COPYING.txt, included in this distribution, for details about the copyright. "Castle Game Engine" is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ----------------------------------------------------------------------------} { TCastleTransform descendant that renders unlit mesh using TCastleRenderUnlitMesh. }unit GameMyMesh; interface uses SysUtils, CastleRenderPrimitives, CastleBoxes, CastleTransform; type { Mesh rendered using TCastleRenderUnlitMesh, not using TCastleScene. This is not generally advised, TCastleScene has much more features and is easier to use than TCastleRenderUnlitMesh. We do this only to test TCastleRenderUnlitMesh with rcForceFixedFunction here. } TMyMesh = class(TCastleTransform) strict private Mesh: TCastleRenderUnlitMesh; public procedure LocalRender(const Params: TRenderParams); override; procedure GLContextClose; override; function LocalBoundingBox: TBox3D; override; end; implementation uses CastleVectors, CastleRenderContext, CastleColors, CastleGLUtils; { TMyMesh -------------------------------------------------------------------- } function TMyMesh.LocalBoundingBox: TBox3D;begin Result := inherited; Result := Result + Box3D( Vector3(-1, -1, -1), Vector3( 1, 1, 1) );end; procedure TMyMesh.LocalRender(const Params: TRenderParams); procedure CreateMesh; begin Mesh := TCastleRenderUnlitMesh.Create(true); Mesh.SetVertexes([ Vector4(-1, -1, -1, 1), Vector4( 1, -1, -1, 1), Vector4( 1, 1, -1, 1), Vector4(-1, 1, -1, 1), Vector4(-1, -1, 1, 1), Vector4( 1, -1, 1, 1), Vector4( 1, 1, 1, 1), Vector4(-1, 1, 1, 1) ], false); Mesh.SetIndexes([ // line loop on Z = -1 0, 1, 1, 2, 2, 3, 3, 0, // line loop on Z = 1 4, 5, 5, 6, 6, 7, 7, 4, // connect Z = -1 with Z = 1 0, 4, 1, 5, 2, 6, 3, 7 ]); Mesh.Color := Yellow; end; var SavedDepthTest: Boolean; SavedLineWidth: Single;begin inherited; SavedDepthTest := RenderContext.DepthTest; SavedLineWidth := RenderContext.LineWidth; RenderContext.DepthTest := true; RenderContext.LineWidth := 5; if Mesh = nil then CreateMesh; Mesh.ModelViewProjection := RenderContext.ProjectionMatrix * Params.RenderingCamera.CurrentMatrix * WorldTransform; Mesh.Render(pmLines); RenderContext.DepthTest := SavedDepthTest; RenderContext.LineWidth := SavedLineWidth;end; procedure TMyMesh.GLContextClose;begin FreeAndNil(Mesh); inherited;end; end.
Code that I want it changed to, but get a crash at line 64 in particular:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{ Copyright 2023-2023 Michalis Kamburelis. This file is part of "Castle Game Engine". "Castle Game Engine" is free software; see the file COPYING.txt, included in this distribution, for details about the copyright. "Castle Game Engine" is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ----------------------------------------------------------------------------} { TCastleTransform descendant that renders unlit mesh using TCastleRenderUnlitMesh. }unit GameMyMesh; interface uses SysUtils, CastleRenderPrimitives, CastleBoxes, CastleTransform; type { Mesh rendered using TCastleRenderUnlitMesh, not using TCastleScene. This is not generally advised, TCastleScene has much more features and is easier to use than TCastleRenderUnlitMesh. We do this only to test TCastleRenderUnlitMesh with rcForceFixedFunction here. } TMyMesh = class(TCastleTransform) published AvatarTransform: TCastleTransform; strict private Mesh: TCastleRenderUnlitMesh; public procedure LocalRender(const Params: TRenderParams); override; procedure GLContextClose; override; function LocalBoundingBox: TBox3D; override; end; implementation uses CastleVectors, CastleRenderContext, CastleColors, CastleGLUtils, GameViewPlay; { TMyMesh -------------------------------------------------------------------- } function TMyMesh.LocalBoundingBox: TBox3D;begin Result := inherited; Result := Result + Box3D( Vector3(-1, -1, -1), Vector3( 1, 1, 1) );end; procedure TMyMesh.LocalRender(const Params: TRenderParams); procedure CreateMesh(AvatarTransform: TCastleTransform); var PlayerAvatarTransform: TCastleTransform; begin PlayerAvatarTransform := AvatarTransform; Mesh := TCastleRenderUnlitMesh.Create(true); Mesh.SetVertexes([ Vector4(0.0, AvatarTransform.Translation.Y, 0.0, 1.0), Vector4(0.0, (AvatarTransform.Translation.Y - AvatarTransform.Direction.Y), 0.0, 1.0) ], false); Mesh.SetIndexes([ // line loop on Z = -1 0, 1 ]); Mesh.Color := Yellow; end; var SavedDepthTest: Boolean; SavedLineWidth: Single;begin inherited; SavedDepthTest := RenderContext.DepthTest; SavedLineWidth := RenderContext.LineWidth; RenderContext.DepthTest := true; RenderContext.LineWidth := 5; if Mesh = nil then CreateMesh(AvatarTransform); Mesh.ModelViewProjection := RenderContext.ProjectionMatrix * Params.RenderingCamera.CurrentMatrix * WorldTransform; Mesh.Render(pmLines); RenderContext.DepthTest := SavedDepthTest; RenderContext.LineWidth := SavedLineWidth;end; procedure TMyMesh.GLContextClose;begin FreeAndNil(Mesh); inherited;end; end.
Can someone please kindly and patiently spell out for me where the code is wrong, rather than telling me I need to read the manual more without explaining what rule I actually broke?
JPF12141999:
Because I know even when I read the API, and it states Vector4 is a 4D vector with 4 floating point values, and made sure to do that, I still get the crash.
I assume it's because I didn't include something else necessary, but it's not obvious at all to a beginner who just follows the book exactly as it is like me.
JPF12141999:
Okay, I made a well-educated guess that perhaps I was using the object's value rather than the object's name to access the variable property, which is not how you should normally do it if I remember that rule correctly from the manual as well as other coding languages,
for example you never say "x equals 5, add 5 to 5" to add 5 to x, but rather "x equals 5, add 5 to x", in fake code obviously and not the syntax of a real language, to make a general point.
However, even after I made that fix I get the same crash, despite having used the correct number of inputs for the Vector4 and the correct syntax to access the object's property, namely "object.property.subproperty", cause I wanted to use only one coordinate of the translation/location and not all 3 at once to make the raycast drawing super precise.
Again, I am assuming it is because I didn't include something else extra, but given that I declared the variable using the "var" keyword, and initialized it with a specific value, in the same exact way as I would do for any variable that the examples show me, I am having a hard time understanding what that something else extra is.
I guessed in the other thread that I needed it to be a class rather than normal variable, but was accused of making random guesses rather than understanding the code correctly, when everyone in that thread was forcing me to make random guesses, because no one was willing to actually spell out anything for me save for a couple of helpful posts from others.
michalis:
--- Quote ---Can someone please kindly and patiently spell out for me where the code is wrong, rather than telling me I need to read the manual more without explaining what rule I actually broke?
--- End quote ---
I did point out the problem in the old thread:
Initialize the field "AvatarTransform" of the instance of class "TMyMesh". It is not initialized now.
See my post on https://forum.lazarus.freepascal.org/index.php/topic,66238.msg507530.html#msg507530 .
Note that if someone reads only this forum thread, they don't really have enough information to help you. You show your modified GameMyMesh unit source code, but the problem is in unit using it, GameViewPlay. Where you, to say it again, do not initialize the field "AvatarTransform" of the instance of class "TMyMesh" .
cdbc:
Hi
@Michalis: in 'GameViewPlay'
--- Quote ---Initialize the field "AvatarTransform" of the instance of class "TMyMesh". It is not initialized now.
--- End quote ---
In method "procedure TViewPlay.Start;", just after:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---DebugAvatar := TDebugTransform.Create(FreeAtStop);I'd put this line:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---AvatarTransform:= TAvatarTransform.Create(FreeAtStop);// or if it's autocreated then something like:AvatarTransform.Init({someparams if required});// or whatever the initializing bit is calledSo that the 'AvatarTransform' is created or initialized, before its first use...
Otherwise I can't see what you mean by "Initialize"?!?
Sorry, just trying to understand.
Regards Benny
Navigation
[0] Message Index
[#] Next page