GetRandomInt - unknown identifier

While creating a code for my device that will randomly play a sound after a timer success I faced a mistake that said that I’m using wrong identifier even though I uncluded the right libraries.
Here is my code
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Verse.org/Native }
using { /Verse.org/Simulation }
using { /Verse.org/Concurrency }
using { /Verse.org/Random }
using { /Verse.org/Verse }
using { /UnrealEngine.com/Temporary/Diagnostics }

Define the main class for handling the timer and audio playback

music_manager := class(creative_device):
# List of songs (audio devices) to choose from
@editable Song1 : audio_player_device = audio_player_device{}
@editable Song2 : audio_player_device = audio_player_device{}
@editable Song3 : audio_player_device = audio_player_device{}
@editable Song4 : audio_player_device = audio_player_device{}
@editable Song5 : audio_player_device = audio_player_device{}

@editable Timer:timer_device = timer_device{}

OnBegin<override>()<suspends>:void =
    # Subscribe to the timer's SuccessEvent
    Timer.SuccessEvent.Subscribe()
    RandomInt:int=GetRandomInt(0,4)

# This function plays a random song from the Songs array
PlayRandomSong(Agent:?agent):void =
    if(RandomInt=0):
        Song1.Play()

Any help would be much appreciated.

Hi. I think you posted this in the wrong forum. This is the Unreal Engine forum, not the UEFN one. You might want to post it there. Just from the code that’s here, I can see one error. Get RandomInt should be set as a variable above OnBegin, so it can be seen by everything. It should be set as: as
var RandomInt: int = 0

then down under OnBegin, it should be set up as:
set RandomInt = GetRandomInt(0,4)

Thank you for your fast response!
Unfortunately, the exact same mistake pops up

1 Like

Maybe this snippet of my code will help you! But I do mine with Float but it’s almost the same!

    ComenzarVotacion(Agent : ?agent):void=
        Print("Comienza el calculo\nEmpezamos obteniendo los numeros aleatorios para cada jugador")
        AllPlayers := GetPlayspace().GetPlayers()
        for (EliminationGamePlayer : AllPlayers):
            if (FortCharacter := EliminationGamePlayer.GetFortCharacter[]):
                temp : float = GetRandomFloat(MinimoAleatorio, MaximoAleatorio)  
                set TemporalAleatorio += array:
                    temp
                
                Print("Numero generado: {temp} \nPara:") 

“MinimoAleatorio” and “maximoAleatorio” They are two float variables created to handle the maximum and minimum, I have it mixed in Spanish and English

I don’t know it just kills my “using { /Verse.org/Random }” anyways
It says that there is no such library in verse. I’m kinda confused ngl

1 Like

I put your code as is in my editor and other things failed, there you have the code you need done well :slight_smile:

Remember to change the name of the main class “PRUEBA” to the one you had! and if not change the name of the verse file to PRUEBA.verse

using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Verse.org/Native }
using { /Verse.org/Simulation }
using { /Verse.org/Concurrency }
using { /Verse.org/Random }
using { /Verse.org/Verse }
using { /UnrealEngine.com/Temporary/Diagnostics }

PRUEBA := class(creative_device):
# List of songs (audio devices) to choose from
    @editable Song1 : audio_player_device = audio_player_device{}
    @editable Song2 : audio_player_device = audio_player_device{}
    @editable Song3 : audio_player_device = audio_player_device{}
    @editable Song4 : audio_player_device = audio_player_device{}
    @editable Song5 : audio_player_device = audio_player_device{}

    @editable Timer:timer_device = timer_device{}

    RandomInt:int = 0

    OnBegin<override>()<suspends>:void =
    # Subscribe to the timer's SuccessEvent
        Timer.SuccessEvent.Subscribe(PlayRandomSong)
        temp:int=GetRandomInt(0,4)
        RandomInt + temp

# This function plays a random song from the Songs array
    PlayRandomSong(Agent:?agent):void =
        if(RandomInt=0):
            Song1.Play()

If you follow me on my tiktok we can help each other if we have any problems :slight_smile:
I’m also relatively new

Alright, thank you so much, you helped a lot.
After a few hours I realized that this code is not optimised so I decided to make an array of sound devices and then, using random number, pick one out of the array and play it.
Tbh, I have no idea on how to get the exact device out of array

1 Like

Now I am also having problems with arrays, I am trying to obtain the largest number within an array… But I know how to solve your problem if you haven’t solved it yet! Do you have discord? :slight_smile:
ID: fali_005