Need help with 1 line of this code

I have this code from Zmackattack for custom enemies. It used to work but with a verse update no longer works. Getting this error:

The line that doesn’t work is this, it has a red error line under the ?:
if (set CurrentProp = MaybeIdleProp?){}

I messaged him and he said: “you need to do something along the lines of this
if (InRound := Player.RoundInfo.InRound?, set Temp = InRound):

I’m not a coder so I don’t know what that means and InRound and all that isn’t even in the original code itself, not sure if he was just using them as a placeholder but I tried formatting it like he said and it didn’t work.

The original code is here:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/AI }
using { /Verse.org/Random }

See Create Your Own Device Using Verse in Unreal Editor for Fortnite | Unreal Editor for Fortnite Documentation | Epic Developer Community for how to create a verse device.

MovementState := enum{Idle, Walking, Attacking}
enemy_info_class := class:
@editable IdleAsset : creative_prop_asset = DefaultCreativePropAsset
@editable WalkAsset : creative_prop_asset = DefaultCreativePropAsset
@editable AttackAsset : creative_prop_asset = DefaultCreativePropAsset
@editable Health : float = 1.0
@editable Damage : float = 0.0
@editable AttackWindupTime : float = 0.5
@editable AttackCooldownTime : float = 0.5

A Verse-authored creative device that can be placed in a level

custom_enemies_device := class(creative_device):
@editable Spawners : creature_spawner_device = array{}
@editable EnableTrigger : trigger_device = trigger_device{}
@editable DisableTrigger : trigger_device = trigger_device{}
@editable var Enabled : logic = true
@editable var EnemyArray : enemy_info_class = array{}
@editable DiedAsset : creative_prop_asset = DefaultCreativePropAsset
@editable TimeToDespawnDied : float = 5.0

# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
    EnableTrigger.TriggeredEvent.Subscribe(Enable)
    DisableTrigger.TriggeredEvent.Subscribe(Disable)
    for (Spawner : Spawners):
        Spawner.SpawnedEvent.Subscribe(CreatureSpawned)  


CreatureSpawned(Agent : agent): void =
    if (Enabled = true):
        if (FortChar := Agent.GetFortCharacter[],Enemy := EnemyArray[GetRandomInt(0,EnemyArray.Length-1)]):
            FortChar.Hide()
            spawn{EnemyLoop(FortChar,Enemy)}


EnemyLoop(FortChar : fort_character,EnemyInfo : enemy_info_class)<suspends>: void =
    var LastTransform : transform = FortChar.GetTransform()
    MaybeProp := SpawnProp(EnemyInfo.IdleAsset,LastTransform.Translation,LastTransform.Rotation)(0)





    var CurrentProp : creative_prop = creative_prop{}
    var CurrentState : MovementState = MovementState.Idle
    var LastState : MovementState = MovementState.Idle

    var WalkSpeed : float = 10.0

    if (set CurrentProp = MaybeProp?):
        loop:
            if (not FortChar.IsActive[]):
                CurrentProp.Dispose()
                PropSpawned :=SpawnProp(DiedAsset, LastTransform)
                Sleep(TimeToDespawnDied)
                if(PropThatNeedToDelete := PropSpawned(0)?){
                    PropThatNeedToDelete.Dispose()
                }
                break
            if (Distance(FortChar.GetTransform().Translation, LastTransform.Translation) = 0.0):
                PlaySpace := GetPlayspace()
                var PlayerNearby : logic = false
                for (Player : PlaySpace.GetPlayers()):
                    if (LoopFortChar := Player.GetFortCharacter[]):
                        if (Distance(FortChar.GetTransform().Translation, LoopFortChar.GetTransform().Translation) < 120.0):
                            if (LoopFortChar.IsActive[]):
                                set PlayerNearby = true

                if (PlayerNearby = true):

                    set CurrentState = MovementState.Attacking

                    CurrentProp.Dispose()
                    MaybeAttackProp := SpawnProp(EnemyInfo.AttackAsset,FortChar.GetTransform().Translation,FortChar.GetTransform().Rotation)(0)
                    if (set CurrentProp = MaybeAttackProp?){}


                    Sleep(EnemyInfo.AttackWindupTime)
                    for (Player : PlaySpace.GetPlayers()):
                        if (LoopFortChar := Player.GetFortCharacter[]):
                            if (Distance(FortChar.GetTransform().Translation, LoopFortChar.GetTransform().Translation) < 120.0):
                else:
                    if (not CurrentState = MovementState.Idle):

                        set CurrentState = MovementState.Idle


                        CurrentProp.Dispose()
                        MaybeIdleProp := SpawnProp(EnemyInfo.IdleAsset,FortChar.GetTransform().Translation,FortChar.GetTransform().Rotation)(0)
                        if (set CurrentProp = MaybeIdleProp?){}


            else:
                if (not CurrentState = MovementState.Walking):
                    set CurrentState = MovementState.Walking


                    CurrentProp.Dispose()
                    MaybeWalkProp := SpawnProp(EnemyInfo.WalkAsset,FortChar.GetTransform().Translation,FortChar.GetTransform().Rotation)(0)
                    if (set CurrentProp = MaybeWalkProp?){}



            set LastTransform = FortChar.GetTransform()
            CurrentProp.MoveTo(FortChar.GetTransform().Translation,FortChar.GetTransform().Rotation,0.1)



(InProp : creative_prop).SwapProp(OutProp : creative_prop)<suspends>: void =
    TempTransform := OutProp.GetTransform()
    if (OutProp.TeleportTo[InProp.GetTransform().Translation,InProp.GetTransform().Rotation]):
    Sleep(0.0)
    if (InProp.TeleportTo[TempTransform.Translation,TempTransform.Rotation]){}



Enable(MaybeAgent : ?agent): void =
    set Enabled = true

Disable(MaybeAgent : ?agent): void =
    set Enabled = false

The error is saying that failure is not allowed in the right side of a set.
This means whatever you set the variable to cannot be diectly evaluated from a failable expression.

Do avoid this, evaluate the failable expression first, then set the value.

NewValue := GetValueFromFailableExpression
set Variable = NewValue

In your case:
if (AttackProp := MaybeAttackProp?, set CurrentProp = AttackProp)

1 Like

Hi, I tried it and it’s not working, as I said idk how to code.

If I replace the old error line with your new one, I get another error saying:

There are 4 original errors, the same error under the question mark on 4 different lines, not just the one. So do you think this error is because the line that is above it had the same error?.. example: