Identical code: one works and one doesn't

I'm hoping that if I show part of my code, someone will be able to see what's wrong with it.

I'm trying to load data from TinyDB at the initialization screen and plot it prior to connecting to my HC-05. There are two lists stored under the name of FWNowList and FWOneHrList. Both have the same source of data, but the latter has points separated by 5 seconds whereas the previous has data separated by 1/2 sec. The procedure plot_FWNow works but the procedure plot_FWOneHr does not. I keep getting a runtime error "Select list item: Attempt to get item number 122 of a list of length 121" From the Do It results, it shows list length is 121, but the "DataDisplay" text show 122 on the screen. The data is properly plotted for plot_FWNow, but the canvas is blank for plot_FWOneHr. I don't understand what is happening, especially since the plot_FWNow works using the same code.

Any help is appreciated!

There is probably a difference between the widths of the two canvases.

Your logic to prevent running off the right edge of the canvas does not work.

Instead of trying to remove list items, set the index limit to
min(canvas.width, length of list ...)

P.S. Component widths might take a little time to settle down after Screen.Initialize. Doing your plot in a Clock Timer triggered at Screen.Initialize migh give your Canvas time to settle down.

3 Likes

Thanks for the reply.

There was a difference and I changed it but in any case, my stored lists haven't been long enough to get to the right side.

I'm making the graph scroll once the data has filled up the canvas, hence the use of "remove from list"

I added that but no joy.

Running out of straws to grab at here.

Try double checking the pen color and line width of the misbehaving Canvas, in case it really is drawing invisible lines.

Reapply Do It to the global variables in the misbehaving plot routine, in case its input got emptied out.

Check the Height of the misbehaving Canvas for odd values like -1.

Replace text block tags for your lists with references to constant global variables with the tags, to avoid the possibility that there is a spelling error between the tags used to fill TinyDB and the tags used to read TinyDB.

I’m not exactly sure what was wrong, but I did remove the statement about getting to the end of the canvas and I put it in another place. All works well now, I wish I knew exactly what was wrong, but……

Thanks for your help and effort!

What does the working code look like?

In addition to getting rid of sensing the right side of the canvas in the plot procedure, there seemed to be some effect do to which canvas was visible as checked in the designer. i made both invisible in the designer and controlled the visibility with code. That seemed to help.

Thanks again!

Thanks for posting your solution!
This should help future users that experience the same problem.

Here's what it looks like on my phone: