# Am I writing this code right?

**URL:** <https://forums.unrealengine.com/t/am-i-writing-this-code-right/823315>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite\
**Created:** [March 26, 2023, 12:23am UTC](https://forums.unrealengine.com/t/am-i-writing-this-code-right/823315 "2023-03-26T00:23:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TZZonerPlayz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TZZonerPlayz](https://forums.unrealengine.com/u/TZZonerPlayz)\
**Post date:** [March 26, 2023, 12:23am UTC](https://forums.unrealengine.com/t/am-i-writing-this-code-right/823315/1 "2023-03-26T00:23:49Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Diru](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/diru/32/910018_2.png) [@Diru](https://forums.unrealengine.com/u/Diru)\
**Post date:** [March 26, 2023, 12:51am UTC](https://forums.unrealengine.com/t/am-i-writing-this-code-right/823315/2 "2023-03-26T00:51:31Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/f/5/bf5aca078d0d520e834bbc3e201e6ea4a3f1b5c5.png)

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:

```auto
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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/3/3/433aed419f4c1f257b28be73e6921dd2ccdfb263.png)

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_

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

```

😁 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:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![TZZonerPlayz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TZZonerPlayz](https://forums.unrealengine.com/u/TZZonerPlayz)\
**Post date:** [March 26, 2023, 12:55am UTC](https://forums.unrealengine.com/t/am-i-writing-this-code-right/823315/3 "2023-03-26T00:55:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Diru](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/diru/32/910018_2.png) [@Diru](https://forums.unrealengine.com/u/Diru)\
**Post date:** [March 26, 2023, 1:05am UTC](https://forums.unrealengine.com/t/am-i-writing-this-code-right/823315/4 "2023-03-26T01:05:24Z")

</div>

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! 😁

---

<div class="post-metadata">

**Author:** ![TZZonerPlayz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TZZonerPlayz](https://forums.unrealengine.com/u/TZZonerPlayz)\
**Post date:** [March 26, 2023, 1:08am UTC](https://forums.unrealengine.com/t/am-i-writing-this-code-right/823315/5 "2023-03-26T01:08:59Z")

</div>

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.
