Forum rules - please read before posting.

Can variables display be formatted?

Hi,
I have an hour (time of day) counter in my game and was wondering if that time integer can be formatted to add leading zeros for single digit hours? 02:00 vs 2:00 for example.

Thanks!
Kay

Comments

  • No, you'd need a string for that.

    A custom script could easily take an AC integer variable and convert it to an AC string variable, however, after making the necessary correction:

    int hourInt = AC.GlobalVariables.GetIntegerValue (2); // e.g. variable 2 is the integer
    string hourString = "0" + hourInt.ToString ();
    AC.GlobalVariables.SetStringValue (3, hourString); // e.g. variable 3 is the string


    For more on manipulating variables through script, see the "Variable scripting" chapter of the Manual.
  • Thanks Chris.
    Do I understand correctly that custom actions are more or less universal, and can be used by anyone to - lets say - convert an int to a string with padded "0" ?
    Much like a plugin that performs a certain task?

    If that is the case, then I am surprised that there isn't already a small library of custom actions that can perform much needed functions that are not native to AC (yet anyway).

    Or am I missing something here?

    Thanks,
    Kay
  • A repository of user-made scripts and Actions can be found in the AC wiki: http://adventure-creator.wikia.com/wiki/Adventure_Creator_Wikia

    Actions are a convenient way of extending AC's functionality, but in many cases (such as this) they're not strictly necessary.

    If you want the code to run every frame, just place it in the Update function of a C# script, and attach it to a GameObject in your scene.

    If you want to control exactly when it runs, place it in a public function of a C# script, attach it to your scene, and use either the Object: Send message or Object: Call event Actions to trigger it.
  • Thanks Chris, I will look into this!

    Regards,
    Kay
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.