How do you show the Counter Value?

  1. 7 months ago

    This example for the Counter Object is pretty cool! My question is…
    How do you set up text to update when the value increases? In the example, it shows "Counter Value."

  2. Hi Tony,

    I think it uses several text boxes on an ascending order. Only “1” is shown and the beginning, the remaining are hidden. Each text box is cued by an individual counter.

    1. Each kind of vegetables will increase 1 to each counter;
    2. Counter 1’s target is set to 1, counter 2’s target is set to 2 and so on;
    3. When any kind of vegetable is dropped to the pot, counter 1 reaches its target and show “1”;
    4. When the second vegetable is dropped, counter 2 reaches its target and show “2”, hide “1” at the same time, and so on.

    Does it make sense? Other ideas are welcome.


  3. Angelo S

    11 Jun 2020 Administrator

    Hello Terry,
    we provide a javascript function to get the value of the counter and another to switch the text of the object dynamically:

  4. Thanks Angelo. Yes I bet JavaScript will do the work. To someone who don’t know how to code like me, I can only make weird interactions from the resources available. :-p

  5. Deleted 6 months ago by Terry C
  6. Edited 7 months ago by James J

    I have the same question and found this thread in hopes to find the answer. Angelo, the answer you provided is confusing, at least for me:

    I went to that link and found an entire post about the entirety of what the code is in PubCoder. I don't see an answer to Tony's question. Is there a code snippet we need to access? What is the line of code?

    I opened up the example that comes with PubCoder, I found this:

    I'll echo Tony's original question. How do you show the Counter value? How do you reflect a change on an object when a counter is updated?

    For an example, if the counter goes to "1", how do we reflect an image to show "1"? When the counter goes to "2" how do we show the number text box show "2"... and so on.

    I looked at the example, looked at interactivity, I could not find where the code is at that tells the text box to change. I tried to look at the code/javascript and all I see is an empty window.

    If all else fails I'll use Terry's suggestion. There might be a more efficient option, but at least Terry has an understandable way to get it to work. I have no idea what to do with the link Angelo provided before. It got overwhelming.

  7. Deleted 7 months ago by James J
  8. 6 months ago

    Angelo S

    30 Jun 2020 Administrator

    Hello James,
    this is the right section:
    to get the value of a counter object "obj6262", you can use pubcoder.getCounterValue($("#obj6262")) but I strongly suggest to read the entire document to understand how to proceed.


or Sign Up to reply!