# vErr:S76: Expected block, got "nearest\_player" following "if" Verse Error

**URL:** <https://forums.unrealengine.com/t/verr-expected-block-got-nearest-player-following-if-verse-error/1989046>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [August 23, 2024, 3:08pm UTC](https://forums.unrealengine.com/t/verr-expected-block-got-nearest-player-following-if-verse-error/1989046 "2024-08-23T15:08:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaydo007](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaydo007/32/968600_2.png) [@Kaydo007](https://forums.unrealengine.com/u/Kaydo007)\
**Post date:** [August 23, 2024, 3:08pm UTC](https://forums.unrealengine.com/t/verr-expected-block-got-nearest-player-following-if-verse-error/1989046/1 "2024-08-23T15:08:05Z")

</div>

Hi to all  
i imported a godzilla model from sketchfab that had a (walking, Idle, Roar), i imported it to UEFN, the animation Idle file is named (godzillaIdle); the animation walk file is named (godzillawalk); the animation attack file is named (godzillaroar), i made a verse code for the NPC, but now am stuck on this problem  
vErr:S76: Expected block, got “nearest\_player” following “if”(3100) [Ln43 ,Col16]  
here’s the code

using { /Verse.org }  
using { /Verse.org/Native }  
using { /Verse.org/Simulation }  
using { /UnrealEngine.com/Temporary/SceneGraph }

# A Verse-authored component that can be added to entities

Godzilla\_behaviour := class(component):

```
# A custom variable you can expose to the editor
@editable
var MyCustomInt<public>:int = 10

# Define variables for Godzilla NPC behavior
var npc : fort_character_entity
var attack_radius : float = 1000.0 # Set the radius for detecting players
var attack_interval : duration = 3.0 # Time between attacks

# Runs when the component should start simulating in a running game.
OnBeginSimulation<override>():void =
    # Run OnBeginSimulation from the parent class before
    # running this component's OnBeginSimulation logic
    (super:)OnBeginSimulation()

    # Assuming the entity this component is attached to is the Godzilla NPC
    npc = fort_character_entity(cast(self.get_entity()))

    # Start NPC behavior
    self.OnBegin()

# Runs the NPC behavior logic
OnBegin():void =
    loop
        # Wait a small interval before checking for players again
        sleep(0.1)

        # Get all players in the world
        players := fort_player_manager().get_all_players()

        # Find the nearest player within the attack radius
        nearest_player := self.FindNearestPlayer(players)

        # Check if the nearest player is valid
        if nearest_player is not none
        {
            # If a player is found, attack them
            self.AttackPlayer(nearest_player)
        }
        else
        {
            # Play idle animation if no players are nearby
            npc.play_animation("godzillaIdle")
        }

# Function to find the nearest player within the attack radius
FindNearestPlayer(players : []fort_character_entity) : fort_character_entity?:
    var nearest : fort_character_entity? = none
    var min_distance : float = attack_radius
    
    # Iterate through all players to find the nearest one
    for player in players
    {
        distance := vector_distance(npc.get_position(), player.get_position())
        if distance < min_distance
        {
            min_distance = distance
            nearest = player
        }
    }
    
    return nearest

# Function to attack the nearest player
AttackPlayer(player : fort_character_entity):void =
    # Ensure player is not none before proceeding
    if player is not none
    {
        # Play the attack animation
        npc.play_animation("godzillaroar")

        # Apply damage to the player (customize as needed)
        damage := 50.0
        player.apply_damage(damage)
        
        # Wait before attacking again
        sleep(attack_interval)

        # Play walk animation as it moves towards the next target
        npc.play_animation("godzillawalk")
    }

```

 ![01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/3/a7352f845b3b34d03ce09be506278fc636af0f59.png)  
 ![02](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/2/5/f25c6d865b9555a59812151c855be44875c63040.png)  
 ![03](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/6/8267bab014726da9fe9db0e7ca24f874475e1a95.png)

---

<div class="post-metadata">

**Author:** ![sonictke](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sonictke/32/924209_2.png) [@sonictke](https://forums.unrealengine.com/u/sonictke)\
**Post date:** [August 28, 2024, 9:47pm UTC](https://forums.unrealengine.com/t/verr-expected-block-got-nearest-player-following-if-verse-error/1989046/2 "2024-08-28T21:47:46Z")

</div>

Hi @Kaydo007 :

The syntax you have in your sample provided is incorrect.

Please refer to: [If | Unreal Editor for Fortnite Documentation | Epic Developer Community](https://dev.epicgames.com/documentation/en-us/uefn/if-in-verse)

You need to surround the condition of the `if` in parentheses. So for example, the line:

```auto
if player is not none

```

Should be

```auto
if (player):

```

The same goes for the `for` macro as well.

Additionally, there are a bunch of other issues, such as `Self` needing the `S` capitalized (which, in your case, you don’t need to specify in the places you’re using it, since you’re not passing the class instance itself as a value - please refer to [Class | Unreal Editor for Fortnite Documentation | Epic Developer Community](https://dev.epicgames.com/documentation/en-us/uefn/class-in-verse#self) for more details). There’s also no such thing as a `none` value, for the line:

```auto
    var nearest : fort_character_entity? = none

```

I think you’re trying to say:

```auto
var nearest:?fort_character_entity = false

```

In Verse, an unset optional evaluates to `false`. Please refer to: [Option | Unreal Editor for Fortnite Documentation | Epic Developer Community](https://dev.epicgames.com/documentation/en-us/uefn/option-in-verse)

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [September 27, 2024, 9:48pm UTC](https://forums.unrealengine.com/t/verr-expected-block-got-nearest-player-following-if-verse-error/1989046/3 "2024-09-27T21:48:41Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
