Hi,
I would like to use GamePlay Tag as string value on my verse code, but Error happens on it.
Please look at the following code:
I prepared GamePlay tag “Tag001” and attached it to a device on the level.
Then, in this Verse code, I tried to change type of GamePlay Tag (tag_view) to string to use Print the tag on screen.
(refering to
Type Casting and Conversion | Epic Developer Community (epicgames.com))
Expected Result: “Tag001” is printed on Fortnite log.
However, it seems that Error occur in “ToString” method and Fortnite crashes.
I cannot know why.
Please help me to find a reason and solution.
Thank you,
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Random }
using { /Verse.org/Verse }
using { /UnrealEngine.com/Temporary/UI }
using { /Fortnite.com/UI }
using { /Verse.org/Colors }
using { /Verse.org/Simulation/Tags }
Tag001 := class(tag){}
<Class> := class(creative_device):
OnBegin<override>()<suspends>:void=
....
....
<Method> ()<suspends>:void =
TagView :tag_view = Device.GetTags()
TagName :string = "{TagView}"
ProjectLog("log_level.Error" , ?Level := log_level.Error)
Print("{TagName}")
# tag_view type is changed to string
ToString(TagView: tag_view):string =
ProjectLog("log_level.Error" , ?Level := log_level.Error)
# Error causes here
return "{TagView}"
Hey, so this is how I do it (but maybe there’s a better solution ?
)
t_chest_model := class(t_chest){}
t_chest_model_suitcase := class(t_chest_model){}
t_chest_model_dumpster := class(t_chest_model){}
GetChestModelTags()<transacts> : []t_chest_model = array{
t_chest_model_suitcase{},
t_chest_model_dumpster{}
}
GetChestModelFromTagView(TagView: tag_view)<transacts><decides>:chest_model=
var RetModel : ?chest_model = false
if(TagView.Has[t_chest_model_suitcase{}]):
set RetModel = option{chest_model.Suitcase}
else if(TagView.Has[t_chest_model_dumpster{}]):
set RetModel = option{chest_model.Dumpster}
RetModel?
chest_model := enum:
Suitcase
Dumpster
ToString(Model: chest_model):string=
case(Model):
chest_model.Suitcase => "Suitcase"
chest_model.Dumpster => "Dumpster"
So basically we’re just converting tag_view
(which can contain many tags) to an enum
(chest_model
) then override the ToString()
method of the enum
.
In my example, it will return the first tag it founds in the list. So it might not suit your needs 
Thank you for your reply.
I tried to use your code on my Verse File but some Error occur.
Let me ask some question about it:
1, Your Code shoud be used before main class, shouldn’t it?
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using{ /Verse.org/Simulation/Tags }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
Tag001 := class(tag){}
# Error: Unknown identifier `t_chest`.(3506)
t_chest_model := class(t_chest){}
t_chest_model_suitcase := class(t_chest_model){}
t_chest_model_dumpster := class(t_chest_model){}
GetChestModelTags()<transacts> : []t_chest_model = array{
t_chest_model_suitcase{},
t_chest_model_dumpster{}
}
GetChestModelFromTagView(TagView: tag_view)<transacts><decides>:chest_model=
var RetModel : ?chest_model = false
# Error: This function parameter expects a value of type tag, but this argument is an incompatible value of type t_chest_model_suitcase.(3509)
# (/localhost/CodeTest:)t_chest_model_suitcase : (/localhost/CodeTest:)t_chest_model
if(TagView.Has[t_chest_model_suitcase{}]):
set RetModel = option{chest_model.Suitcase}
# Error: This function parameter expects a value of type tag, but this argument is an incompatible value of type t_chest_model_dumpster.(3509)
# (/localhost/CodeTest:)t_chest_model_dumpster : (/localhost/CodeTest:)t_chest_model
else if(TagView.Has[t_chest_model_dumpster{}]):
set RetModel = option{chest_model.Dumpster}
RetModel?
chest_model := enum:
Suitcase
Dumpster
ToString(Model: chest_model):string=
case(Model):
chest_model.Suitcase => "Suitcase"
chest_model.Dumpster => "Dumpster"
# A Verse-authored creative device that can be placed in a level
EnumToString := class(creative_device):
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
# TODO: Replace this with your code
Print("Hello, world!")
Print("2 + 2 = {2 + 2}")
2, As the above code comments, some Error occur on the code.
Error1: What is class “t_chest” type? Where is this defined and what is this used for?
Error2: it seems that “t_chest_model_suitcase” and “t_chest_model_dumpster” type cannot be used for “Has” member of “tag_view” class. Is there any reason that these types are used here?
Thank you.
Hey, yeah you’re right I forgot to send you send this :
t_chest := class(tag){}
But I assumed you knew a bit of Verse, the code is specific for my use and not meant to be copy pasted but rather analyzed and understood 
But if you want to test it still, move everything outside your device, or in another empty file 