Am I writing this code right?

Hello there,

I need help. I am having struggle and basically, Visual Studio Code is giving me a error that says Functions declared at this scope are not supported and I think I’m writing this code right.

Here is my code:

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }

hello_there_device := class(creative_device):

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void =


        HealPlayer() : void =
            Playspace: fort_playspace = GetPlayspace()
            AllPlayers: []player = Playspace.GetPlayers()
            if (FirstPlayer : player = AllPlayers[0]):
                if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                    FortniteCharacter.Damage(100.0)

If you have a fix for this then, can you please let me know? and also, let me know if I wrote this code wrong of if this is a bug in the Verse coding languauge, Thank you.

This error is because you’re creating a function inside of OnBegin.
Every “Tab space” you make is like opening a new door with a room inside.

image

Everything has to be inside of the class, wich is the red line. If you in the same red-tab-space write something like bye_there_device := class(creative_device) in programming would be like if you create another verse script. (Someone more experienced can correct me if i’m wrong, i’m just learning code 1 year ago as a hobby)

Then, inside the red color starts the code, where you should write your functions, OnBegin it’s a void function, like you wrote with HealPlayer().

The correct code should be like this:

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }

hello_there_device := class(creative_device):

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void =


    
    HealPlayer() : void =
        Playspace: fort_playspace = GetPlayspace()
        AllPlayers: []player = Playspace.GetPlayers()
        if (FirstPlayer : player = AllPlayers[0]):
            if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                FortniteCharacter.Damage(100.0)

(Do you see it? HealPlayer is in the same Tab of OnBegin, that means he’s out of OnBegin function)

image

Now, as you can see, OnBegin shows a problem on “=”. That’s because OnBegin is empty, and if you don’t write nothing there you’re doing basically nothing. Then: How do I add that script to make it work?

Since you created a new function HealPlayer() you can summon it inside of OnBegin to make it work onbeginthegame

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void =
        HealPlayer()

:grin: That should be do the trick!

About those colored lines

Everything you create are known by the next doors you create. If you create a variable inside of the pink line, you can use it in green or yellow one, like you do with FirstPlayer or AllPlayers that are being used inside green line, but they’re created in the pink one. but this don’t work backwards. Something you create in yellow will not work in the pink or green one.

TL;DR:

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }

hello_there_device := class(creative_device):

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void =
        HealPlayer()

    
    HealPlayer() : void =
        Playspace: fort_playspace = GetPlayspace()
        AllPlayers: []player = Playspace.GetPlayers()
        if (FirstPlayer : player = AllPlayers[0]):
            if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                FortniteCharacter.Damage(100.0)
2 Likes

Ok, thank you. Also, is it ok if I copy the correct code that you provided?

If you’re starting to programming i’d recommend you to read it and re-write it yourself to keep concepts and memorize how verse works, but sure, go ahead and use it! :grin:

Ok, thank you. Also, can you please tell me how do I mark a message as a solved message so that people would know that the problem has been solved? Thank you.