I wouldn’t convert the days passed to a string, except for when it’s needed by the GUI, and then just save the days passed number to a daysPassed variable, as so:
but I’m not really sure what you mean here… I don’t think it’s what I need… ??
What i’m trying to do is pass the information in UserInformation.GetDaysPassed()
Which is on my UserInformation script like this:
public static string GetDaysPassed()
{
today = System.DateTime.Now ;
//days between today and start date -->
System.TimeSpan elapsed = today.Subtract(startDate) ;
double days = elapsed.TotalDays ;
Debug.Log ("It Was this Manys Days Since you Asked Me That Last " + days.ToString("0"));
return days.ToString("0") ;
}
But then in my main script I’m dong this:
In the If statement I want to check the days past to basically see if the current day is one day ahead of my saved SetStartDate… hopefully that made sense?
case "AreYouAspaceship":
LoadInformation.LoadLastThingSaid01 ();
LoadInformation.GetStartDate ();
UserInformation.GetDaysPassed();
if (KITT_IsPlayingAudioRecording == false && KITT_IsRecordingAudio == false) {
//Check if it Is Michael And Surveillance Mode Is OFF And That Shut Up Mode Is OFF
if (KITTmodesObject.isMichael == true && KITTmodesObject.SurveilanceModeActive == false
&& KITTmodesObject.KITT_isSpeaking == false && KITTmodesObject.ShutUpMode == false
&& KITTmodesObject.KITT_SaidThis == false) {
if ((lastQorA == "AreYouAspaceship" || UserInformation.LastThingSaid01 == "AreYouAspaceship")
&& (UserInformation.startDate > UserInformation.today)){
KITTvoiceBox.YouHadAlreadyAskedThatResp ();
//Negative So Subtract 1 Point From The Mood Level
KITTmodesObject.KITT_MoodLevel--;
Debug.Log ("Why Is Michael Asking Me This Again? That Is Most Anoying");
} else if (KITTmodesObject.isMichael == true && KITTmodesObject.SurveilanceModeActive == false
&& KITTmodesObject.KITT_isSpeaking == false && KITTmodesObject.ShutUpMode == false
&& KITTmodesObject.KITT_SaidThis == false) {
Debug.Log ("Michael Asked ---- Are You A Spaceship");
KITTvoiceBox.AreYouAspaceshipResp ();
//Negative So Subtract "1" point From The Mood Level
//Stating the obvious does not earn any "Brownie Points"
KITTmodesObject.KITT_MoodLevel--;
lastQorA = "AreYouAspaceship";
SaveInformation.SetStartDate ();
UserInformation.LastThingSaid01 = ("AreYouAspaceship");
SaveInformation.SaveLastThingSaid01();
print ("I Will Remember This");
}
}
I meant, that by removing the .ToString() from the UserInformation.GetDaysPassed() function, you are able to compare the return value in your main script. In it’s current form, your UserInformation.GetDaysPassed() returns a String and not a value that can be compared using operators other than not-equals-to and equals-to.
thanks @TBranflakes
I don’t really want to use the OnGUI at all I just have it there temporarily to test… but on start up it spits out some insane number I don’t know where it’s getting that from… Bear with me… i’ll try to post my scripts
I have a SaveInformation Script
using UnityEngine;
using System.Collections;
public class SaveInformation {
public static void SaveLastThingSaid01(){
PlayerPrefs.SetString ("lastQorA01", UserInformation.LastThingSaid01);
}
public static void SaveLastThingSaid02(){
PlayerPrefs.SetString ("lastQorA02", UserInformation.LastThingSaid02);
}
/*public static void SetStartDate()
{
UserInformation.startDate = System.DateTime.Now ; //save the start date ->
PlayerPrefs.SetString("DateAsked", UserInformation.startDate.ToString()) ;
Debug.Log ("Setting Start Date Now");
}*/
public static void SetStartDate()
{
if(PlayerPrefs.HasKey("DateAsked")) //if we have the start date saved, we'll use that
UserInformation.startDate = System.Convert.ToDateTime(PlayerPrefs.GetString("DateAsked")) ;
else //otherwise...
{
UserInformation.startDate = System.DateTime.Now ; //save the start date ->
PlayerPrefs.SetString("DateAsked", UserInformation.startDate.ToString()) ;
}
}
}
And A LoadInformation Script
using UnityEngine;
using System.Collections;
public class LoadInformation {
public static void LoadLastThingSaid01(){
UserInformation.LastThingSaid01 = PlayerPrefs.GetString ("lastQorA01");
}
public static void LoadLastThingSaid02(){
UserInformation.LastThingSaid02 = PlayerPrefs.GetString ("lastQorA02");
}
public static void GetStartDate()
{
UserInformation.startDate.ToString( PlayerPrefs.GetString ("DateAsked"));
Debug.Log("I Got The Start Date Michael");
Debug.Log (UserInformation.startDate.ToString());
}
}
Then my UserInformation Script
using UnityEngine;
using System.Collections;
public class UserInformation : MonoBehaviour {
public static string LastThingSaid01{
get; set;
}
public static string LastThingSaid02{
get; set;
}
public static System.DateTime startDate;
public static System.DateTime today;
void Start(){
LoadInformation.GetStartDate ();
}
/*public static void SetStartDate()
{
startDate = System.DateTime.Now ; //save the start date ->
PlayerPrefs.SetString("DateInitialized", startDate.ToString()) ;
print ("Setting Start Date Now");
}*/
public static string GetDaysPassed()
{
today = System.DateTime.Now ;
//days between today and start date -->
System.TimeSpan elapsed = today.Subtract(startDate) ;
double days = elapsed.TotalDays ;
Debug.Log ("It Was this Manys Days Since you Asked Me That Last " + days.ToString("0"));
return days.ToString("0") ;
}
}
I uploaded a screen grab of the insane number the onGUI spits out Vs what I think it should spit out on startup which I would have thought was my public static void SetStartDate ()
But maybe i’m doing something wrong in how I’m saving and loading it maybe??
It’s also in this specific part of my if statement I want to be able to cross reference the: UserInformation.startDate > UserInformation.today
I thought I might have ben on the right track with what I was attempting there to compare the current date with my saved date fro when the last time the question was asked.
Just by taking a quick glance at your code again it appears that in your UserInformation script, you’re only assigning the today variable within the GetDaysPassed function, and you’re only assigning startDate when the GetStartDate function is called. Therefore, calling UserInformation.startDate and UserInformation.today will always return null until after those functions are called.
As far as getting that random number, I’m not sure. I don’t typcically deal with using double values in my personal coding. I prefer floats/ints.
using UnityEngine;
using System.Collections;
public class UserInformation : MonoBehaviour {
public static string LastThingSaid01{
get; set;
}
public static string LastThingSaid02{
get; set;
}
public static System.DateTime startDate;
public static System.DateTime today;
/*public static void SetStartDate()
{
startDate = System.DateTime.Now ; //save the start date ->
PlayerPrefs.SetString("DateInitialized", startDate.ToString()) ;
print ("Setting Start Date Now");
}*/
public static string GetDaysPassed()
{
today = System.DateTime.Now ;
//days between today and start date -->
System.TimeSpan elapsed = today.Subtract(startDate) ;
double days = elapsed.TotalDays ;
return days.ToString("0") ;
}
}
Thanks @TBranflakes,
I’m still not certain on how to go about getting this to do quite what I want it to do?
It seems like when My script reaches the save part of the Switch statement then the OnGUI stuff changes to zero.
I put some debugs in my code and as near as I can tell the player prefs is saving and loading my date the question was asked: (See Attached)
But why on start up of my game session the OnGUI is not showing the days passed based on it’s equation I just don’t get.
All I want to do is find out if the number of days since I asked the question is “One Day” and if atleast one day has fully passed since I asked that question ignore the first part of the if statement where he says “You Already Asked Me That” and go onto the 2nd part where it gives a different answer and then saves the new date time in order to start the process over again… sounds simple enough but this blasted script Is driving me nuts… been at it 4 days now.
It sounds like you may just need to do some heavy debugging on accessing the days passed function. Try creating a small temporary debugging script that uses the GetDaysPassed button, but rather than getting the PlayerPrefs or worrying about load/saving, just use public variables that can be modified in the inspector.
Without being able to open up the project to run it myself, I can only speculate what may be the issue.
Thanks @TBranflakes,
I did put Debugs pretty much everywhere… I kinda think of them as KITT’s thoughts lol
If you look at the attached you can see that it’s loading in the saved date the question was asked but just below it it still spits out that ridiculous number in the OnGUI crap.
Sooooo… as near as I can tell from the Debugs it is saving and loading my date’s but why I can’t get that into usable data for my if statement is my real issue & why that OnGUI is spitting out that “736333” number… I don’t get that.
This is my entire case statement in the bladed part is where I want to check for if the date is at least one day past before moving onto the 2nd part of the if statement. I thought I was onto something with that UserInformation.startDate > UserInformation.today
case "AreYouAspaceship":
LoadInformation.LoadLastThingSaid01 ();
LoadInformation.GetStartDate ();
UserInformation.GetDaysPassed();
if (KITT_IsPlayingAudioRecording == false && KITT_IsRecordingAudio == false) {
//Check if it Is Michael And Surveillance Mode Is OFF And That Shut Up Mode Is OFF
if (KITTmodesObject.isMichael == true && KITTmodesObject.SurveilanceModeActive == false
&& KITTmodesObject.KITT_isSpeaking == false && KITTmodesObject.ShutUpMode == false
&& KITTmodesObject.KITT_SaidThis == false) {
if ((lastQorA == "AreYouAspaceship" || UserInformation.LastThingSaid01 == "AreYouAspaceship")
&& ([B]UserInformation.startDate > UserInformation.today[/B])){
KITTvoiceBox.YouHadAlreadyAskedThatResp ();
//Negative So Subtract 1 Point From The Mood Level
KITTmodesObject.KITT_MoodLevel--;
Debug.Log ("Why Is Michael Asking Me This Again? That Is Most Anoying");
} else if (KITTmodesObject.isMichael == true && KITTmodesObject.SurveilanceModeActive == false
&& KITTmodesObject.KITT_isSpeaking == false && KITTmodesObject.ShutUpMode == false
&& KITTmodesObject.KITT_SaidThis == false) {
Debug.Log ("Michael Asked ---- Are You A Spaceship");
KITTvoiceBox.AreYouAspaceshipResp ();
//Negative So Subtract "1" point From The Mood Level
//Stating the obvious does not earn any "Brownie Points"
KITTmodesObject.KITT_MoodLevel--;
lastQorA = "AreYouAspaceship";
SaveInformation.SetStartDate ();
UserInformation.LastThingSaid01 = ("AreYouAspaceship");
SaveInformation.SaveLastThingSaid01();
print ("I Will Remember This");
}
}
Okay so I’m starting to believe that the problem is actually the start date. Try the code below. You should return 6 days difference. If this works, then the problem is the startDate.