Instantiating a struct in Verse

I’m trying to make a struct array, but the one thing that I cannot get to work is the instantiating the struct. I’ve looked at the struct documentation and I’ve just copied and pasted what they had about instantiating it but it still gives off an error (Data definitions at file scope must specify their value domain.) and (This archetype instantiation constructs a class that has the ‘transacts’ effect, which is not allowed by its context.)

below is what I have up to the struct instantiation.

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

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

@editable
Coordinates := struct {
X : float = 0.0
Y : float = 0.0
}
Position := Coordinates{X:= 1.0, Y:= 1.0}

No problem like this

Coordinates := struct:
    X : float = 0.0
    Y : float = 0.0

hello_world_device := class(creative_device):
    Test : Coordinates = Coordinates {
        X:= 0.0,
        Y:= 10.0
    }
2 Likes

Well I longer get that previous error, but now I get an error that pops up when trying to build it:
Unhandled attribute type

I can confirm that the struct causes it as when I remove that code the error is no longer there.

Could you show us the full code? It’s possible that this struct affects other parts of your code in some way. Cray_Opeta’s code worked fine for me, so seeing the context might help identify an issue.


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

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

@editable
Coordinates := struct {
    X : float = 0.0
    Y : float = 0.0
}


PickMap := class(creative_device):

    Position : Coordinates = Coordinates {
        X:=1.0,
        Y:=3.0
    }
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Print("Game Started")
2 Likes

It works if you remove @editable. Is there any reason to use it?

Well my plan was to have a struct of teleporter device array (for random tp locations) and have a variable array of that struct to make it easier to create new levels/maps

You mean something like this?

Coordinates := struct {
    X : float = 0.0
    Y : float = 0.0
}


PickMap := class(creative_device):

    var Positions : []Coordinates = array{
        Coordinates { X:=1.0, Y:=3.0 } 
    }
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Print("Game Started")


    AddPosition(coordinates: Coordinates)<decides> : void =
        set Positions = Positions + array{coordinates}

Not entirely, I meant as in I could add the values through the editor.
Similar to this (except this doesn’t have the struct array):

I want to use the struct array as a way to organize each map with their own set of teleporters, and to easily implement the actual teleporting.

If I understood right, @editable is using to mark editable properties of device class, not their types:

1 Like

Yup which is why I had the @editable in the code from before but it gave off that build error about the unhandled attribute type. Any ideas?

Levels := struct {
    @editable
    Teleporters : []teleporter_device = array{teleporter_device{}}
}




PickMap := class(creative_device):

    Level : []Levels = array{Levels  {
    }}

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

Putting @editable above ‘Level’ gives an error (The editable attribute is not supported for classes that aren’t concrete.)
and having it inside the struct doesn’t seem to be doing anything

1 Like

This works fine for me:

Coordinates := struct<concrete> {
    @editable
    X : float = 0.0

    @editable
    Y : float = 0.0
}

hello_world_device := class(creative_device):

    @editable
    Positions: []Coordinates = array{}

image

6 Likes

Ah now it works, I just needed . Thanks a lot.

3 Likes

Is it possible to get this to work with a device as one of the editable props? Like so:

capture_item_spawner := struct<concrete> {
    @editable
    Device: capture_item_spawner_device = capture_item_spawner_device {}

    @editable
    Level: int = 0
}

my_game_device := class (creative_device) {
    @editable
    CaptureItemSpawners: []capture_item_spawner = array {}
}

Cause right now I can’t seem to get this working, it shows that there are 2 members to each editable item in the array but it’s only showing Level:

editable

I wasn’t sure if its not possible yet, or if it should be and it’s broken or I’ve just set it up wrong.

1 Like

Hi @Resykz,

It looks like there is a bug in Verse when referencing creative devices inside structs. This is being worked on and will be fixed in an upcoming release.

6 Likes

Good to know, thanks for the update!

I was having a similar problem where I couldn’t assign the device to a device property in an array of structs, I got this warning “Illegal TEXT reference to a private object in external package”. I changed the struct to be a class and it worked fine :+1:

2 Likes