Need Help with Final Line of Code Not Accepting a Period

Hi everyone,

I have still been working diligently on fixing and updating my Toy Story 2 like game based on everyone’s feedback.

I have added code to make the collectible objects disappear when you touch them fine, and the nails have their collision boxes changed to fit them more properly,

but when I added code to check if the player is touching the ground using the raycast script from the platformer example that comes with the game engine at the very end of “gameviewplay.pas”, I get an error message at compile time about the very final line expecting a semicolon but getting a period, even though again, using the same example from the “platformer” folder in the official Castle Game Engine public download, the very final line that ends “gameviewplay.pas” in that example is in fact typed with a period and not a semicolon.

On top of this, it worked fine and compiled perfectly in the same exact position (at the very end of the file) before I added the code to raycast whether the player is touching the ground, so I have no clue why it isn’t working now.

Does anyone know why it is acting weirdly for my particular project?

The link to the updated Github project is:

You are missing an end somewhere in your file. Use the editor to highlight the begin/end tags and see what it thinks is the corresponding begin/end.

Awesome! Thank you so much for the quick response!

I will definitely work on fixing that.

It isn’t a tricky problem, to be honest…

Yeah, I get that too - that’s why I fixed it ASAP.

I know as always the right thing to do for any project is simply to pay attention to how many “begins” and “ends” I have, so that way I don’t make clumsy errors like these in the future :slight_smile:

1 Like

Glad you fixed the problem. :smile:

Me too. The game design should be smooth sailing from here on out, and I bet you will enjoy playing as Sandy Cheeks from SpongeBob!

Okay, so now that is fixed, but I still need help figuring out what the appropriate conditions are for the bounding box, because just using the way it was directly from the platformer game doesn’t work when I tell it to play a sound file that I know actually works, when you jump - no sound is played at all.

I would assume this is because it is still registering me as touching the ground, so do you guys know the proper conditions for the bounding box to check whether the player is on the ground or not in a 3D game like this, and not a 2D game like a platformer?

Thank you very much in advance.

EDIT: I added a code about the bounding box’s Z dimension for the third component of the first parameter rather than “0” from the platformer, guessing the third component meant the third dimension/the Z dimension, but unfortunately it still doesn’t work correctly. I am assuming I am missing something else, but don’t know exactly what.

EDIT 2: I think I figured out what I might be doing wrong: I assumed that the second component of a Vector3 meant the Y axis like on a flat surface, but I think it’s actually the Z axis given how the raycast direction is (0, -1, 0) for straight down, and not (0, 0, -1).

EDIT 3: It still doesn’t work after doing the dimensions according to the way the second vector does it, so I have no clue what else I am doing wrong, but I am assuming it is something extra I am missing to make it work in 3D and not 2D like the platformer example.

Okay, I figured it out myself - it was because I didn’t actually include the function in the Update procedure, but the actual function body was correct after the last fix.

However, even after I fixed that particular detail, I can still spam the jump sound an infinite amount of times, as opposed to it playing only when you first jump off the ground.

Does anyone know why this is, again I am assuming it is because it is still registering as you touching the ground, in which case I will change the length of the vector until it plays the correct amount of times (only once per jump)?

EDIT: Even after shortening the length to 0.1 and then 0.01 for the down component of the second vector, I still get an infinite amount of jump sounds, so I am not sure what else I need to fix.

I had a similar problem when it looped the werewolf-howl.wav and I couldn’t stop it as my cats freaked out.

It looks like TCastleSoundSource offers a non looping Play. You could also get the length of the sound, and then in a subclass override the Update method and stop playing after that amount of time.

Okay, awesome!

It doesn’t loop if you just press space once, so I am not entirely sure that is the actual problem, but I can always try any help I get.

Yeah, and actually in my example there is no sound source, just the sound itself that is being played, so it is definitely not the actual problem.

Do you know how else I might fix it then?

On top of that, the other sounds I loaded into the game like for picking up an item play just once without looping, using the same exact code (about Playing a sound and then using the sound’s name with no other additions needed), so I really have evidence that isn’t the actual problem.

Thank you for your help though!

As for sounds: To be clear, both with TCastleSoundSource and without TCastleSoundSource, one can play sounds as looping and non-looping.

Looking at your code gameviewplay.pas you just play all sounds using SoundEngine.Play which is totally good. It plays the sound without looping.

If you don’t want to “spam” the sound, then do not play it before the previous sound invocation has not yet finished playing. Is this what you want? For this, you could use TCastlePlayingSound and either observe its TCastlePlayingSound.Playing state or watch for its TCastlePlayingSound.OnStop notification. For example, like this:

  • Declare SoundJumpPlaying: TCastlePlayingSound as private field in your view.
  • Create it in your view Start, like
    SoundJumpPlaying := TCastlePlayingSound.Create(FreeAtStop);
    SoundJumpPlaying.Sound := SoundJump;
  • Instead of SoundEngine.Play(SoundJump) you can now play it through SoundJumpPlaying and abort if it already plays:
    if not SoundJumpPlaying.Playing then

As with my past answers, remember that above is a pseudocode, not tested. Don’t just paste it into your application in any place and expect to work. Please try to understand it, experiment with it (maybe in a new application) to make sure you know how to use it.

Okay, awesome! That solution works better, because it addresses the actual problem more precisely;

However, I want it to not play the sound period, not just after the first sound has stopped, if you aren’t touching the ground, but right now it spams the sound like I still am touching the ground when I am in mid-jump.

That is what I wanted help fixing in the first question.

IE: How do I make the game register I am not touching the ground correctly, so that way the sound plays exactly only after I have first jumped off the ground and never any other times?