Page 1 of 1

Loading saved variables as integers

Posted: Mon Oct 31, 2016 9:23 pm
by thegamerguynz
Hi guys,

I'm trying to write a custom persistent data script, I've got the variables to save, but how do i load them as integers for application?

Re: Loading saved variables as integers

Posted: Mon Oct 31, 2016 10:27 pm
by Tony Li
Hi,

Use DialogueLua.GetVariable and DialogueLua.SetVariable. Add ".AsInt" to the end of the GetVariable function to get the variable as an integer.

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class MyImportantNumberScript : MonoBehaviour {

    public int myNumber;
    
    void OnRecordPersistentData() {
        DialogueLua.SetVariable("MyNum", myNumber);
    }
    
    void OnApplyPersistentData() {
        myNumber = DialogueLua.GetVariable("MyNum").AsInt;
    }
}