0
Not a bug

global counters not working

SeanB 10 років тому оновлений 10 років тому 6
You may already be tracking and fixing this, but just in case.

  1. Create a global counter on page 2
  2. add a button tap > counter add 1 to it, then counter display
works as expected. now,
  1. on other pages add this action to any element:
  2. behavior counter display, target our counter, execute on page load "yes"
Run in Design mode
Expected: increment counter on page 2 to X, navigate to other pages and back and continue to see X on all pages that execute counterDisplay

Actual: global counter behaves as a page counter - not available to other pages, value is discarded after leaving page 2.

This is urgent for me as I want to use it to allow user to toggle off app-wide audio. See http://feedback.interactbuilder.com/topic/531056-how-can-you-play-page-and-narration-audio-together/?user_satisfaction=1#satisfaction_rating_edit

Відповідь

Відповідь
Not a bug
Hi Sean,
Here's a way to get around this problem:

1. On the pages that have CounterDisplay on page load, add a text element, and use that as the target of the CounterDisplay behavior. The CounterDisplay behavior has a separate field for Target and Counter, and the Counter field is where you can select the global counter that will display in the Target text element. So the global counter keeps track of the value, but the text elements on each page act as a container for displaying the value.

2. On the pages that use CounterDisplay on page load, go to the page properties, and set the Save Page State field to No. This makes sure that the "on page load" behaviors happen each time the page opens.
Відповідь
Not a bug
Hi Sean,
Here's a way to get around this problem:

1. On the pages that have CounterDisplay on page load, add a text element, and use that as the target of the CounterDisplay behavior. The CounterDisplay behavior has a separate field for Target and Counter, and the Counter field is where you can select the global counter that will display in the Target text element. So the global counter keeps track of the value, but the text elements on each page act as a container for displaying the value.

2. On the pages that use CounterDisplay on page load, go to the page properties, and set the Save Page State field to No. This makes sure that the "on page load" behaviors happen each time the page opens.
Super I will try this tonight, thanks!
Had time, it works! This would make a great youtube (if there's not one already).

Let me try to summarize the action setup sequence:

When you choose tap > Counter > CounterDisplay, you're not displaying the counter element directly. You need to use a text element as the Target. Then you choose the counter as the source to get the value from. The counter value is inserted into the text element.

One other cool thing I just learned. On the global counter's "home page", if you do a CounterDisplay on page load without setting it to any value, it nicely receives the value of zero. Thank you! This is very valuable IMO. So you can chain some conditionals to that CounterDisplay-onpageload. The 1st time you hit the page, on page load you automatically have a value of zero - not undefined, to work with, and without having to explicitly set it to zero. That's important because IB conditionals can't work with undefined, as far as I know. So this trick allows you to return 2nd+ time to counter's home page, and the current value is preserved. Otherwise, if you had to do an onpageload > CounterSet = 0, then every time you came to its home page it'd get reset to zero, :(  regardless of the Save Page State property.

Everything above I have tested and it works perfectly. If you don't want to see the counter's text field visually, just position it offscreen.
That's interesting! Thank you so much for the notes! I might add a tutorial in the future about including a global counter whose value shows on each page.
Hmm as I reread this I realize the conditionals are still checking the value of the counter, not it's display element. But whatever, it works as desired :).