# Need Help with Final Line of Code Not Accepting a Period

**URL:** https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217
**Category:** 3D
**Created:** [May 31, 2024, 2:36pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217 "2024-05-31T14:36:23Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [May 31, 2024, 2:36pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/1 "2024-05-31T14:36:23Z")

</div>

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:

> **[GitHub - JPF12141999/Toy-Story-2-Ripoff-Game: Ripoff of Toy Story 2: Buzz...](https://github.com/JPF12141999/Toy-Story-2-Ripoff-Game)**
>
> Ripoff of Toy Story 2: Buzz Lightyear to the Rescue, which takes place in the SpongeBob Universe instead. - JPF12141999/Toy-Story-2-Ripoff-Game

---

<div class="post-metadata">

### Author: ![edj](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/edj/32/1701_2.png) [@edj](https://forum.castle-engine.io/u/edj)
#### Post date: [May 31, 2024, 2:41pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/2 "2024-05-31T14:41:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [May 31, 2024, 2:41pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/3 "2024-05-31T14:41:59Z")

</div>

Awesome! Thank you so much for the quick response!

I will definitely work on fixing that.

---

<div class="post-metadata">

### Author: ![tudarcat](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/t/54ee81/32.png) [@tudarcat](https://forum.castle-engine.io/u/tudarcat)
#### Post date: [May 31, 2024, 2:56pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/4 "2024-05-31T14:56:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [May 31, 2024, 2:59pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/5 "2024-05-31T14:59:01Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![tudarcat](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/t/54ee81/32.png) [@tudarcat](https://forum.castle-engine.io/u/tudarcat)
#### Post date: [May 31, 2024, 3:07pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/6 "2024-05-31T15:07:52Z")

</div>

Glad you fixed the problem. 😄

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [May 31, 2024, 3:08pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/7 "2024-05-31T15:08:35Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [May 31, 2024, 3:21pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/8 "2024-05-31T15:21:16Z")

</div>

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.

> **[GitHub - JPF12141999/Toy-Story-2-Ripoff-Game: Ripoff of Toy Story 2: Buzz...](https://github.com/JPF12141999/Toy-Story-2-Ripoff-Game)**
>
> Ripoff of Toy Story 2: Buzz Lightyear to the Rescue, which takes place in the SpongeBob Universe instead. - JPF12141999/Toy-Story-2-Ripoff-Game

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [June 3, 2024, 10:27am UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/9 "2024-06-03T10:27:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [June 3, 2024, 10:48am UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/10 "2024-06-03T10:48:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![edj](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/edj/32/1701_2.png) [@edj](https://forum.castle-engine.io/u/edj)
#### Post date: [June 3, 2024, 3:04pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/11 "2024-06-03T15:04:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [June 3, 2024, 3:17pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/12 "2024-06-03T15:17:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [June 3, 2024, 3:21pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/13 "2024-06-03T15:21:14Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [June 3, 2024, 3:24pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/14 "2024-06-03T15:24:51Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [June 4, 2024, 9:24pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/15 "2024-06-04T21:24:27Z")

</div>

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](https://github.com/JPF12141999/Toy-Story-2-Ripoff-Game/blob/main/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](https://castle-engine.io/apidoc/html/CastleSoundEngine.TCastlePlayingSound.html) 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

```delphi
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:

```delphi
if not SoundJumpPlaying.Playing then
   SoundEngine.Play(SoundJumpPlaying);

```

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.

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [June 4, 2024, 9:30pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/16 "2024-06-04T21:30:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JPF12141999](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/jpf12141999/32/1218_2.png) [@JPF12141999](https://forum.castle-engine.io/u/JPF12141999)
#### Post date: [June 4, 2024, 9:36pm UTC](https://forum.castle-engine.io/t/need-help-with-final-line-of-code-not-accepting-a-period/1217/17 "2024-06-04T21:36:59Z")

</div>

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?
