Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    Code:
    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

    #2
    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?
    Last edited by gamepainters; 09-21-2020, 03:29 PM.

    Comment


      #3
      I wrote my functions that seem to work:
      Code:
      //-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      //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...
      Last edited by Coldscooter; 09-21-2020, 04:29 PM.

      Comment


        #4
        I finally found a native class that does all this conversion for me
        Code:
        CloudStorageBase

        Comment


          #5
          glad you found it, nice

          Last edited by gamepainters; 09-21-2020, 05:46 PM.

          Comment


            #6
            Coldscooter 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.
            Originally posted by gamepainters View Post
            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?
            gamepainters 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.
            Check out Himeko Sutori, the upcoming tactical RPG where you control armies of over 100 unique characters.

            Comment


              #7
              Originally posted by Nathaniel3W View Post
              Coldscooter 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.
              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=4bgA..._channel=Doyen)

              Do you by any chance know where that setting is?

              Comment


                #8
                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.
                Check out Himeko Sutori, the upcoming tactical RPG where you control armies of over 100 unique characters.

                Comment

                Working...
                X