Cant get variable to string to work correctly

I’m trying to set up a very basic calendar system for my game using events.


The game takes place over 30 days.


Here’s the start of the Common Event:


kpdZCcp.png



Here’s the control variable that sets the variable to a string in the picture above:


muEqoSH.png



To test it I made a test event to see if it would work, +1 is added each time the player "rests", increasing the variable by 1, which changes the string in the common event.


RBU2BpI.png



Here’s the event in action:


CJYaerZ.png

fKMmo1G.png



Selecting yes:


OqJxZhD.png



Saying yes again:


JzRvChM.png



Every time I select yes, a 1 is added to the end, the displayed string does not change beyond that no matter how many times I did it.


What am I doing wrong?
As soon as you changed the variable to store a string, it is no longer a number that can be counted.


As a result the command does exactly what it is ordered to - add a "1" to the end of the string.


If you want to keep counting numbers, you cannot change the variable to a string.


So basically you need to use more than one variable and only change the final result to a script in a variable that doesn't need to be counted.
As soon as you changed the variable to store a string, it is no longer a number that can be counted.


As a result the command does exactly what it is ordered to - add a "1" to the end of the string.


If you want to keep counting numbers, you cannot change the variable to a string.


So basically you need to use more than one variable and only change the final result to a script in a variable that doesn't need to be counted.

Thanks, that makes sense, i'll give that a try 🙂  
Assuming:

  • Variable 1 is day
  • Variable 2 is month
  • Variable 3 is day of week
  • Variable 4 is printed date
Spoiler
var day = $gameVariables.value(1);
var month = $gameVariables.value(2);
var dayOfWeek = $gameVariables.value(3);
switch(month) {
  case 1:
    month = "January";
    break;
  case 2:
    month = "February";
    break;
  case 3:
    month = "March";
    break;
  case 4:
    month = "April";
    break;
  case 5:
    month = "May";
    break;
  case 6:
    month = "June";
    break;
  case 7:
    month = "July";
    break;
  case 8:
    month = "August";
    break;
  case 9:
    month = "September";
    break;
  case 10:
    month = "October";
    break;
  case 11:
    month = "November";
    break;
  case 12:
    month = "December";
    break;
  default:
    month = "Error";
    break;
}

switch(dayOfWeek) {
  case 1:
    dayOfWeek = "Sunday";
    break;
  case 2:
    dayOfWeek = "Monday";
    break;
  case 3:
    dayOfWeek = "Tuesday";
    break;
  case 4:
    dayOfWeek = "Wednesday";
    break;
  case 5:
    dayOfWeek = "Thursday";
    break;
  case 6:
    dayOfWeek = "Friday";
    break;
  case 7:
    dayOfWeek = "Saturday";
    break;
  default:
    dayOfWeek = "Error";
    break;
}

$gameVariables.value(4) = dayOfWeek + ", " + month + " " + day;



Call the above code when you want to print the date. It does nothing fancy like "st" or "th" after dates. It does, however, have no spaces after the resulting string, so you could check the day and add them manually.


You would be responsible for setting day of week manually, as well as changing the code to reflect your chosen variables. You will get "Error" in your date string if you mess up the month or day of week. This also lets you expand to use more than one month and if you need year, just add a variable for it at the top and add it to the date string.


Please note this is UNTESTED. I'm at work and used my morning break time to toss this together. But, it should let you just increment your date and day of week. Just use a conditional branch to check if day of week is = 7 and if it is, set it to 0. If you do that, when you increment, it will go to 1, which is where you would need it to be.


It does change how you're doing things, but should eliminate the need for the big calendar-check common event.

Original thread: https://forums.rpgmakerweb.com/threads/cant-get-variable-to-string-to-work-correctly.59574/