Loading saved variables as integers

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
thegamerguynz
Posts: 12
Joined: Mon Sep 19, 2016 8:34 pm

Loading saved variables as integers

Post 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?
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading saved variables as integers

Post 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;
    }
}
Post Reply