ATVO by Appgineering
Download
Read-only

Trying to make a widget visible/invisible using code

4 posts 3,076 views Started 02 Jul 2020, 21:43
Showing 1–4 of 4 posts
Olivier T.
Original poster

Hey guys!

I've been reading through a bit of those threads and always found a solution to my problems so far, but for some reason, the proposed solution either doesn't work or I'm doing something wrong.

Basically, I want to make a widget that shows the fastest lap whenever a new fastest lap is set. The twist is that, even though there is a trigger, it operates during practice, qualy and race sessions, so I want to make sure that this widget only appears during the race.

I have whipped up the following code, but setting the trigger to execute it, or even setting a button to execute the code, at least to make the widget display, doesn't make the widget appear:

IEntitySessionResult result = (IEntitySessionResult) value; 
	 
		var session = result.Session.Type.ToString();
		var widget = item.Theme.Widgets.Find("Fastlap");
	
		if (session == "Race")
		widget.IsVisible = true;
	
		return "";

Am I doing something wrong here?

Emmanuel S.
Reply #1
· edited

Try with this:
widget.AnimateShow("0");
widget.AnimateShow("1000");

And
widget.AnimateHide("0");
widget.AnimateHide("1000");

For me only 0 value work, but value is for fade-in or fade-off

Nick Thissen Appgineering
Reply #2

The AnimateShow and AnimateHide should allow you to do this indeed. Not sure why any other value than 0 is not working for you, it should work just fine. I will test it again.

Olivier T. wrote:
Basically, I want to make a widget that shows the fastest lap whenever a new fastest lap is set. The twist is that, even though there is a trigger, it operates during practice, qualy and race sessions, so I want to make sure that this widget only appears during the race.

An easier way to do this would be to block the trigger execution with a condition script. In the action where you show the widget, you can select a script as the Condition. The script should return true or false - if it returns false the action will not be executed.

The script would then simply check the session name and return true only if it's "Race", similar to what you already had.

I do something similar in the ATVO theme, you can take a look at that too. Instead of a script however I use a Condition Flag that is set/unset with a button.

Olivier T.
Reply #3
· edited

Nick Thissen wrote:
An easier way to do this would be to block the trigger execution with a condition script. In the action where you show the widget, you can select a script as the Condition. The script should return true or false - if it returns false the action will not be executed.

The script would then simply check the session name and return true only if it's "Race", similar to what you already had.

Thanks for your reply!

So basically, something like that should work with Action Type "ChangeWidgetVisibility" -> "Show"?

var session = result.Session.Type.ToString();
 
 if (session == "Race")
 
 return true;
 
 else
 
 return false;
Archive · Read-only

New replies have moved to Discord.