Forum rules - please read before posting.

Having trouble hiding a menulabel based on a variable

edited May 2014 in Technical Q&A
Heyo,

I've built a little system that puts a notifications badge on a button in my UI, much like how it looks on an iPhone. When I click the button (called Dossier Button) to open the associated menu (called Dossier), I want to clear the badge.

In the script that governs the Dossier menu, it has this:


AC.MenuLabel notifier;

void Start() {
notifier = (AC.MenuLabel) PlayerMenus.GetElementWithName("Dossier Button", "Notifications badge");
}

void Update() {
//see whether there are any notifications, and if so, display the badge
string notifications = GameObject.FindWithTag(Tags.persistentEngine).GetComponent<RuntimeVariables>().GetVarValue(0);

if (notifications != "0") {
notifier.isVisible = true;
}
else {
notifier.isVisible = false;
}
}


This works perfectly when I modify the value from the AC Variables menu. However, it does not work when I call it from the Menusystem.cs like this:


public static void OnMenuEnable (Menu _menu)   {
if (_menu.title == "Dossier") {
//clear the notifications badge
GameObject.FindWithTag(Tags.persistentEngine).GetComponent<RuntimeVariables>().SetValue(0, "0");
}


Turning the badge off manually in the same code block does nothing either. Any idea why that is?

Comments

  • Try calling _menu.Recalculate (); after setting the value - also, why not set the correct visibility in OnMenuEnable as well?

    Word of warning: 1.32 changes the syntax slightly for setting/getting variables.  Your new code would be:

    GlobalVariables.GetBooleanValue (0)
    and
    GlobalVariable.SetBooleanValue (0, false);
  • Thanks! The recalculate wasn't actually necessary but your reply got me thinking about what sort of variable I'm using. You said the syntax would change to GetBooleanValue but actually it would be GetStringValue since my variable stores how many notifications there are, not just if there are any.

    However, I had set up that variable as an integer, but writing:

    int notifications = GameObject.FindWithTag(Tags.persistentEngine).GetComponent<RuntimeVariables>().GetVarValue(0);

    resulted in the error 'cannot convert string to int', so I wrote all the code to work with a string, but the original variable was still an integer. Changing that around actually fixed it. :)
  • edited May 2014
    I updated the code for 1.32 like you said and it still works perfectly. Plus now that the variable type can be explicitely referenced in the command (.SetIntegerValue) I put everything back to integers so I can do +1 and other math with the value. Much easier than using a string for that I reckon ha. Cheers!
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.
Do NOT follow this link or you will be banned from the site!