Convert String to Array<byte> (for cloud saves)

I’m just looking into implementing Steam cloud saves. The functions to write/read to the cloud use Array<byte> for the file contents:


native function bool WriteUserFile(string UserId,string FileName,const out array<byte> FileContents);

So how do i convert my big string blob into an Array<byte>?

Thanks

How are you going to assign anything into the last parameter its a const.?
const out array<byte> FileContents

when you make a call to that function and input the id and name what do you log in the last parameter coming out, does it already have info in it if the right id and name is put into it?

I think if you put in the id and the name it’s going to spit out the proper info in the out parameter?

I wrote my functions that seem to work:



//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//Converts a string into an Array<byte>
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function Array<byte> StringToByteArray(string textBlob)
{
    local int character;
   local Array<byte> byteArray;

   while (Len(textBlob) > 0) {
      character = Asc(Left(textBlob, 1));
      byteArray.AddItem(character);
      textBlob = Mid(textBlob, 1);
   };

   return byteArray;
}

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//Converts a byte array into a string.
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function String ByteArrayToString(Array<byte> byteArray)
{
   local byte _byte;
   local String _string;

   foreach byteArray(_byte) {
      _string $= Chr(_byte);
   }

   return _string;
}


However the problem with this is if the file contents is greater than 1,000,000 characters long, it will trip-up the infinite-loop protection and crash the engine.

Any ideas? There must be some native handling for this somewhere…

I finally found a native class that does all this conversion for me :slight_smile:


CloudStorageBase

glad you found it, nice:)

@ there’s a setting somewhere that lets you tell the engine how many calls to the same function to tolerate. I had to increase that to stabilize my pathfinding algo.

And thanks for telling us about the CloudStorageBase class. I was thinking about doing cloud saves, but I just didn’t want to mess with that yet. I’m sure this will help when I get around to it.

when you make a const out parameter, you’re actually just telling the engine “Don’t make another copy of this variable. I’m not going to change the information held inside it. I just want to look at the data while this function is running.” It’s a best practice for minimizing memory usage and making the game run faster.

Oh interesting! It was mainly an issue for me when deserializing huge save games, where players had build almost city-sized structures across the map (like this: https://www.youtube.com/watch?v=4bgAJdol0QA&ab_channel=Doyen)

Do you by any chance know where that setting is?

That’s pretty amazing that one of your players made that. It feels good to see people having fun with something you made.

I responded to your other post about this. But I’ll post here too just in case some future UE3 user needs the answer: You need to set RUNAWAY_LIMIT and RECURSE_LIMIT in UnCorSc.cpp.