The width of a drawing area is generally only set with the second (same) command. Why?

Hello! I've been struggling with the same problem for about 6 hours now and despite various tests and attempts at tricks I've come to no conclusion. I use the length of the text in braille to calculate the length of the drawing area on which the text should be displayed, and the drawing area should not be unnecessarily long. The app basically calculates the width of the area correctly for the first command, but after assigning the calculated area width to the area when I call it up as a property, it gives me the original, unchanged width. If I execute the same command again, but only manually by calling it up with the key, everything is calculated, transferred and displayed correctly. I can't see any comprehensible algorithm behind it and can't get any further. I've already tried hiding the area before assigning it, to no avail, and also tried using the clock function - no success.

What am I not understanding here??? Please help! :-()

My German is very weak, so I am guessing your global variable purposes.

You use a global variable to hold the current width of the place you will show the Morse code?

I suspect it can't keep up with the actual width.

I suggest instead using a value procedure that measures it dynamically, and replace all references to the global variable with calls to the new procedure.

This will help eliminate timing problems.

Unfortunately, this has nothing to do with the variable types and doesn't help (tested). I always have to call the function twice to get an exact view, the first time always gives a distorted output. This software is enough to drive you to despair. You spend many hours of your life on such simple tasks and go around in circles because some illogical basis, the cause of which is invisible, is not allowing you to progress.

Can you provide an example text?
Also I did not understand, what exactly you are calculating?

Are you looking for the length of the text? But why don't you just use the length method from the text drawer?

Is this an empty text block or is there an empty string inside?
Screenshot_20240820_134209_DuckDuckGo

It would be nice to switch the language to English before taking a screenshot...

Generally Use the companion app and Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.

export_and_upload_aia

.

It takes time for the width to change.

The translation thing isn't really well done; he does some things and doesn't do others.

This morning I noticed that the width of the canvas is actually assigned the first time, so that is not the problem. Unfortunately, when the drawing function is called for the first time, immediately after calculating and assigning the width of the canvas, the points are drawn with a completely distorted scale. Then the second time it is called, it is exactly right.

Show us everything

well, switching the language can only translate the blocks, but obviously not your german variable names

it looks like you ignored my previous questions... or are you still trying to answer them?

Taifun

No, not ignored. I have created a stripped down version and translated everything into English as far as possible. I am uploading this here and hope that someone will recognize what my problem is, or at least recognize what is not working. Of course, I also hope to get answers about WHY.
LED_15_Kop.aia (82.3 KB)

I am posting some bad code here:
blocks

Note the attributes of TitleBlock:


It's monospace, 14.0 point Fontsize, and Fill Parent Width nested in a series of other Arrangements set to Fill Parent Width up to the responsive Screen Width, whatever that turns out to be at run time.

So it looks like you are doing some typography here.

From your math, it looks like you want to set Canvas1.Width to fit Titleblock.Text, assuming 30 pixels Width per character plus 15 per space.

You start out with Canvas1.Width set to 5000 pixels:
image

You decline allowing movement outside the Canvas:
image

Of particular interest is your looping attempt at recursion at the bottom of the procedure:


Fortunately, the three way AND will never come back true because the second and third sockets will never simultaneously be true. They contradict each other. Canvas1.Width can not be both smaller than a low value and higher than a high value at the same time.

That turns out to be fortunate, saving you from an infinite recursion that might have overflowed memory or sent your app into a coma.

This entire approach is backwards.
Typically, you accept the Width of the Canvas as given, and adjust your Fontsize and text positioning and content to fitthe Canvas, using proportions.

Here is some reading material covering the AI2 timing model that you are abusing:

Somewhere in there is discussion of the screen refresh cycle.

OK, the AND test was clearly a careless mistake on my part. It should have been OR including this AND. Now I've redesigned the query for the Canva width and embedded it in a small time loop. It's working at the moment and I can finally continue working on the actual program. Attached is the improved version. Thank you for your help, although I still don't really understand why the width assignment is taken into account so late in
LED_15_Kop(2).aia (81.9 KB)
the drawing process.

Thank you for your help, even though I still don't really understand what exactly caused the problem, probably everything in the phone is a bit sluggish. :slight_smile: