Question about optional variable usage in Verse

My requirement is that I want to provide an optional parameter in my interface and judge whether the optional parameter is valid inside the interface. I thought of a way of writing:

MyFunction<public>(?MyOptionalTransform : ?transform = false)
    if (T : transform = MyOptionalTransform):
        # MyOptionalTransform is valid
    else:
        # MyOptionalTransform is not valid

I thought this would work because it didn’t show any error in my VSCode. But when I try to launch my session, it showed this error:

  1. LogWindows: Error: appError called: Assertion failed: GetIntNum(Property, IntType) < MaxZeroComparisons [File:D:\build++Fortnite\Sync\Engine\Source\Runtime\CoreUObject\Private\Serialization\UnversionedPropertySerialization.cpp] [Line: 166] Unexpectedly large property type encountered __verse_0x7D844C3C_Elem1

This direct an error in the CPP file which I do not have permission to check and modify. Did I write the syntax in the wrong way or this is Verse’s fault?

Untested but I think you would want to do:

MyFunction<public>(MyOptionalTransform : ?transform)
    if (MyOptionalTransform?):
        # MyOptionalTransform is valid
    else:
        # MyOptionalTransform is not valid

But this is not an optional parameter. I have to pass false as MyOptionalTransform in usage.

I’m confused - putting the ? in front of transform makes it an optional.

If I put ? in front of MyOptionalTransform and give it a default value, it will be an optional parameter which means when I try to use this interface, I do not need to pass this variable. If I put ? in front of transform. when I use this interface, I have to pass this variable but can use false as its value.

So I try to combine them, so it can be an optional parameter also I know its default value is false, so that means it’s invalid.

As far as I am aware I don’t think Verse supports optional parameter types yet?

The Print function can take optional parameters, right? Like the color and the duration, they both are optional.

You’re right I see that they are declaring the parameters the same way you are too.

I see - I misunderstood your question as just needing an optional type, not a there being an optional parameter. Not too sure how to do what you’re looking for.

Post the entire code, as the sample code you’ve provided above is invalid syntax (i.e. the return type and body of the function haven’t been specified). Additionally, if you’re actually utilising an interface, the inheriting classes need to use the override specifier for the inherited functions. For example:

my_interface := interface:
    MyFunction(?MyTransform : ?transform) : void

my_class := class(my_interface):
    MyFunction<override>(?MyTransform : ?transform = false) : void =
        # ...

I haven’t tested the above, so give it a try and let me know how you go.

Oh, I forgot to add the return type. Actually, the code in my project is like yours. There is no error in my VSCode, and I assume this should work perfectly. But this will stop you from launching your session and give you a weird error log like the picture above.

I’ve been using optional parameters and return types in my classes (not interfaces, but presumably the syntax would be the same?).

Here’s some examples in case it’s helpful.

An example of a function returning an optional - Tracked_Prop is my own class.

GetTrackedProp(pLocation : vector3) : ?Tracked_Prop =
    # Some code which checks locations of props...

    If (some condition):
        # If it finds a matching prop, return it (as an optional).
        return option{aTrackedProp}

    else:
        # If it didn't find one, return false
        return false

An example of code calling the above function and using the optional.

    aBoxOpt := GetTrackedProp(aPropMan.GetTransform().Translation)

    if (aBox := aBoxOpt?):
        aBox.SetPropMan(aPropMan)
    else:
        # Can do something if the optional didn't have a value.

Hey @landscapecmy, I tested the code posted by @Ben85 and it seems to work fine. I get no compile errors. If your code is like theirs, I suspect that you may have an issue not related to this code.

My suggestion would be to create a new forum post and post all your code if you’re still getting that error. Feel free to DM me a link to the post after you do and I can get the right person to take a look.

2 Likes

It is no compile error but you can not launch your session. If you try to launch it, it will show an error on in Fortnite when loading your session. Can you try this? If it works let me know. Thanks for replying!

Oh, I just checked it again, it works now. I don’t know why it didn’t before.


This is exactly what I wrote before, but it didn’t work before.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.