You can’t do that because string and int does not share any superclass in common. However, I made this code a while back. Try to use it to convert from string to int
StringToInt(IntInString: []char): int=
# if 'IntInString' is negative
if (IntInString[0] = '-'):
var Value: int = 0
loop:
set Value -= 1
if (ToString(Value) = IntInString):
Print("{Value}")
return Value
# if 'IntInString' is positive
else:
var Value: int = -1
loop:
set Value += 1
if (ToString(Value) = IntInString):
Print("{Value}")
return Value
It seems it will work well.
However, when I try to use your method in my code, some Error occur as the attached pictures.
Could you give me advice how to use it?
Thank you.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
song2 := class(creative_device):
@editable
AudioPlayerDevice<public> : []audio_player_device = array{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
# TODO: Replace this with your code
var number : string = "1"
var Index : int = StringToInt(number)
StringToInt(IntInString: []char): int=
# if 'IntInString' is negative
if (IntInString[0] = '-'):
var Value: int = 0
loop:
set Value -= 1
if (ToString(Value) = IntInString):
Print("{Value}")
return Value
# if 'IntInString' is positive
else:
var Value: int = -1
loop:
set Value += 1
if (ToString(Value) = IntInString):
Print("{Value}")
return Value