'Add line break' added to PlayMaker ES2 Append Raw

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
Abelius
Posts: 11
Joined: Sat Apr 14, 2018 12:26 am

'Add line break' added to PlayMaker ES2 Append Raw

Post by Abelius »

Hi there,

I thought this could be useful for some PlayMaker users. A convenient way to add a line break to the Append Raw action. I use it to make Debug Logs, so it's nice to have each message in its own line.

Code: Select all

[ActionCategory("Easy Save 2")]
	public class AppendRaw : FsmStateAction
	{
		[RequiredField]
		[Tooltip("The raw string we want to append to a file.")]
		public FsmString saveValue;
        [Tooltip("Add a line break at the end of the string.")]
        public FsmBool addLineBreak = true;
        [Tooltip("The name or absolute path of the file we want to append our raw string to. If the file doesn't exist, it will be created.")]
		public FsmString filename = "defaultFile.txt";
		[Tooltip("This event is called if an error occurs.")]
		public FsmEvent ifError = null;

		public override void Reset()
		{
			saveValue = null;
			base.Reset (); // Ensure that base.Reset() is called when done.
		}

		public override void OnEnter()
		{
			try
			{
                if (addLineBreak.Value)
                {
                    ES2.AppendRaw(saveValue.Value + "\r\n", filename.Value);
                    base.OnEnter(); // Ensure that base.OnEnter() is called when done.
                    Finish();
                }
                else
                {
                    ES2.AppendRaw(saveValue.Value, filename.Value);
                    base.OnEnter(); // Ensure that base.OnEnter() is called when done.
                    Finish();
                }
            }
			catch(System.Exception e)
			{
				if(ifError != null)
				{
					LogError(e.Message);
					Fsm.Event(ifError);
				}
			}
		}
	}
Thanks.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: 'Add line break' added to PlayMaker ES2 Append Raw

Post by Joel »

Many thanks for this, I'm sure it will come in useful to a lot of people!

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked