OnPageLoad CounterVar is being set to 0 on new page


#1

Hello,

For my master thesis I’m doing an app that counts points if the user completes some challenges.

This variable is shown in the bottom-right-corner, I have transformed this in a Master that’s being used on multiple pages.

I’ve made a global variable CounterVar that’s set to 0.
If the challenge has been completed counterVar sets text to [[CounterVar+10]].

That is what I want and works great.

But if I go into another page of the app the CounterVar sets back to 0. So all received points are being lost. Does anyone know how I can fix this?

https://dy65rx.axshare.com

Thanks a lot!!!


#2

Without seeing the actual .rp file, it’s hard to troubleshoot what exactly is happening.

To try isolating the issue, temporarily add a button to the page that has the problem. Set the button to change its text to the global variable on click. Go through the established process of incrementing the global variable and navigate to the page. Click the button. If it shows the original, default value, then there’s an event somewhere that’s resetting the variable.

If it shows the updated value, there’s either an event that is resetting the text widget or there isn’t an event to set the text widget with the value of the global variable (ex, OnPageLoad set text = globalVar).


#3

If you open the (x) Console tab on the left you can see exactly what’s wrong: you never update the variable!

You have actions that change the text of the widget to [[CounterVar + 10]] but you can see in the console where it shows current variable values CounterVar never changes. In the trace below where you can see all cases that get executed, none of them apparently contain an action that actually changes the variable value.

For example, here’s the case when I click the “Start” button and the text changes from “0p” to “10p”

OnClick
Case 1
Hide PopUP_Welkom fade 600 ms
Set text on (Puntentelling)/(Rectangle) equal to "[[CounterVar+10]]"

You set the text but CounterVar is still equal to 0 and never changes. What you probably want is this:

OnClick
Case 1
Hide PopUP_Welkom fade 600 ms
Set value of variable CounterVar equal to "[[CounterVar + 10]]"
Set text on (Puntentelling)/(Rectangle) equal to "[[CounterVar]]"

Update the variable first then just show the current value of the variable in the text.

Of course I don’t read Dutch so I don’t know if I’m doing it correctly or triggering the right thing.


#4

Ah! Yes! The console! I keep forgetting about that little feature… oops :blush:


#5

Ohmygod that totally worked!!! Thank you so much !!

https://dy65rx.axshare.com/#c=2


closed #6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.