How do I copy a final count value from the script variable to the AC variable?
I tried to do it, but a CS1061 error occurs in SetValue.
private IEnumerator CollectWithTimeLimit()
{
float elapsedTime = 0f;
while (elapsedTime < timeLimit)
{
if (bossLive==false)
{
AC.GVar var = AC.GlobalVariables.GetVariable(49);
if (var != null)
{
var.SetValue(Mathf.FloorToInt(elapsedTime)); // an error CS1061 appears in ''SetValue''.
}
yield break;
}
elapsedTime += Time.deltaTime;
yield return null;
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
There is no SetValue function for the GVar class - IntegerValue / FloatValue etc properties are used instead:
Here I found a problem, the time in minutes and seconds is being converted, for example 7 seconds is being given a value in the AC variable of 7 seconds when the correct value should be 07 seconds. And minutes 1 when the correct value is 01. So when it is one minute and seven seconds, in the AC variable it should be 01:07 and not 1:7
private IEnumerator CollectWithTimeLimit()
{
float elapsedTime = 0f;
while (elapsedTime < timeLimit)
{
if (boss1Live == false)
{
// Total time in seconds
int totalSeconds = Mathf.FloorToInt(elapsedTime);
// Calculates minutes and seconds
int minutes = totalSeconds / 60;
int seconds = totalSeconds % 60;
// Store in Adventure Creator global variable
AC.GVar varMinutes = AC.GlobalVariables.GetVariable(49); // 49 is for minutes
AC.GVar varSeconds = AC.GlobalVariables.GetVariable(50); // 50 is for seconds
if (varMinutes != null)
{
varMinutes.IntegerValue = minutes; // Store the minutes
}
if (varSeconds != null)
{
varSeconds.IntegerValue = seconds; // Store the seconds
}
Debug.Log($"Time: {minutes} minutes and {seconds} seconds"); // Display the formatted time
yield break;
}
elapsedTime += Time.deltaTime; // Update the elapsed time
yield return null; // Wait for the next frame
}
Debug.Log("Timeout! You didn't collect the object in time.");
}
}
It's not an issue on the AC side - the problem is that you're using the Integer type to record your values. "01" is not an Integer - "1" is, and for the former you would need a String type.
To convert your elapsedTime variable and format it into a time string, use the TimeSpan.FromSeconds function as explained in this (non-AC) thread:
https://stackoverflow.com/questions/463642/how-can-i-convert-seconds-into-hourminutessecondsmilliseconds-time
it worked thank you