Prop Spawner

Hey all,

Hope everyone is having a good day. I’m trying to create a prop spawner that will randomly spawn a prop in one of three locations and i’m having issues. I’m quite new to UEFN and Verse.

I’m not the best programmer out there. Previously experience being HTML and Javascript.

This is my code for the script

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

# A Verse-authored creative device that can be placed in a level
Tape_spawner := class(creative_device):

    @editable
    tapeProp: creative_prop = creative_prop{}

    @editable
    tapeAsset : creative_prop_asset = DefaultCreativePropAsset
    

        
    TapeLocationDecider():void=    
        var RandomInt:int = GetRandomInt(1,3)
         if (RandomInt = 1):
             tapelocation:vector3 = vector3{X := -1084.0, Y:= 2587.999982, Z:= 3160.0}
         else if(RandomInt = 2):
             tapelocation:vector3 = vector3{X := 0.0, Y:= 0.0, Z:= 0.0}
         else if(RandomInt = 3):
             tapelocation:vector3 = vector3{X := 0.0, Y:= 0.0, Z:= 0.0}
     

    
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
    tapeProp.Dispose()
             
    var spawnTapeLocation:vector3 = vector3{Translation:= tapelocation}

    SpawnProp(tapeAsset,transform{Translation:= spawnTapeLocation})
    

     
        

Can you be more specific about the error your getting? or what is not working? Right off the bat i can see that your OnBegin is outside of the device’s scope…

1 Like

TapeLocationDecider Should be turned to this

    TapeLocationDecider()<transacts>:vector3=    
        var RandomInt:int = GetRandomInt(1,3)
            if (RandomInt = 1):
                tapelocation:vector3 = vector3{X := -1084.0, Y:= 2587.999982, Z:= 3160.0}
            else if(RandomInt = 2):
                tapelocation:vector3 = vector3{X := 0.0, Y:= 0.0, Z:= 0.0}
            else:
                tapelocation:vector3 = vector3{X := 0.0, Y:= 0.0, Z:= 0.0}

And var spawnTapeLocation:vector3 = vector3{Translation:= tapelocation} should become var spawnTapeLocation:vector3 = TapeLocationDecider()

Also as Lil Wikipedia Mentioned you need to tab the OnBegin a bit to the right so its in device scope

2 Likes

Thanks, i’m still getting used to Verse. Most errors went away once I had the formatting correctly.

Thanks for your help. combined with Lil Wikipedia’s formatting. The code does work.

Once again thanks for your helps really appreciate it :slight_smile:

1 Like