Post Reply 
Initializing AVars
11-13-2024, 10:02 PM
Post: #1
Initializing AVars
Is there a good way to initialize AVars that may not exist in PPL apps? I've tried a couple things:

Code:

EXPORT RESET()
BEGIN
 AVars("MyVar") = 17;
END;

EXPORT Symb()
BEGIN
 PRINT(MyVar);  //Syntax error if MyVar doesn't exist at compile time.  Works correctly otherwise
END;

Code:

EXPORT MyVar;
EXPORT RESET()
BEGIN
 AVars("MyVar") = 17;
END;

EXPORT Symb()
BEGIN
 PRINT(MyVar);  //Compiles if MyVar is declared, but just prints 0 because the AVars seems to be shadowed.
END;

Code:

EXPORT MyVar = AAVars("MyVar"); //crashes calculator if MyVar doesn't exist

I suppose I could explicitly wrap all references in a AVar() call, but I'd rather avoid that if at all possible.
Find all posts by this user
Quote this message in a reply
11-15-2024, 07:03 AM
Post: #2
RE: Initializing AVars
It will be difficult for you to get an answer to your question when you ask it in the way that you did. Provide more context. What do you want to achieve, what is your goal? Once it is known what you are aiming for, you may find an answer or a completely different solution (e.g., without using AVars). You used the term "...PPL apps." Do you mean an app with its own icon launched from the Application Library, or are you referring to a PPL program launched from the Program Catalog or command line?

If we're talking about an app that you launch using an icon visible in the Application Library, then initializing AVars variables is relatively simple.

We will return to this once you provide more details.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
11-15-2024, 06:15 PM
Post: #3
RE: Initializing AVars
I'm talking about apps in the Application Library. I've noticed that the connectivity kit can be a bit inconsistant about sending AVars with apps, so I'm looking for a way to work around this.

I don't really want to use global variables since they get reset every time I edit the program, which was getting on my nerves, but maybe they'd be fine for the release version?

Maybe I could manually copy AVars to global variables at every entry point to the program, like this:

Code:

MyVar;

RESET()     //We need to ensure RESET() is called the first time the app is run
BEGIN
 AVars("MyVar"):="Default Value";
END;

SomeEntryPoint()
BEGIN
 MyVar:=AVars("MyVar");
 //do stuff
 AVars("MyVar):=MyVar;
END;

But is there a better way to do this?
Find all posts by this user
Quote this message in a reply
11-16-2024, 05:33 PM
Post: #4
RE: Initializing AVars
(11-15-2024 06:15 PM)keldor314 Wrote:  I've noticed that the connectivity kit can be a bit inconsistant about sending AVars with apps, so I'm looking for a way to work around this.
Could you elaborate on the issue you're experiencing with the connectivity kit and AVars? There are many applications that rely on this functionality and seem to work flawlessly. I've never encountered any problems with my applications as well.

If your only goal is to read and write data to the same variables and you simply want to ensure that this information is not lost after the program editing, then the variables should be integrated into the app from the start. They should not be created dynamically in the code but rather defined in the Home view of the application. This approach ensures they are permanently associated with the app and are initialized immediately upon its installation. You can then reference these variables in the program code without needing to use AVars(), as they do not require declaration.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
11-16-2024, 11:07 PM
Post: #5
RE: Initializing AVars
(11-16-2024 05:33 PM)komame Wrote:  
(11-15-2024 06:15 PM)keldor314 Wrote:  I've noticed that the connectivity kit can be a bit inconsistant about sending AVars with apps, so I'm looking for a way to work around this.
Could you elaborate on the issue you're experiencing with the connectivity kit and AVars? There are many applications that rely on this functionality and seem to work flawlessly. I've never encountered any problems with my applications as well.

If your only goal is to read and write data to the same variables and you simply want to ensure that this information is not lost after the program editing, then the variables should be integrated into the app from the start. They should not be created dynamically in the code but rather defined in the Home view of the application. This approach ensures they are permanently associated with the app and are initialized immediately upon its installation. You can then reference these variables in the program code without needing to use AVars(), as they do not require declaration.

I don't remember my exact steps, but I do know that when I try to send my app from my calculator to the emulator, the AVars aren't copied at least some of the time. This results in the app failing to compile/run until I manually recreate every AVar referenced in the code.

My preferred way of handling this would be to create AVars in the RESET() function, which is called when you reset the app from the app browser, and can also be called from inside START() if needed. This works in isolation, but and usage of an AVar "directly" in an expression anywhere will prevent the app from compiling and running.

The app is a moderately complex parametric 3D grapher, so there are currently about 20 AVars between function definitions and bounding boxes and camera and grid definitions. I expect the number to increase as I add options for drawing axes and bounding boxes, as well as multiple functions to plot.
Find all posts by this user
Quote this message in a reply
11-17-2024, 06:35 PM
Post: #6
RE: Initializing AVars
In my opinion, you might have made a mistake while copying or sending the application. The Connectivity Kit maintains its own copy of the application, refreshing it whenever the calculator is connected (or the emulator is started) and keeping it until you manually refresh it again. Any changes made in the emulator or on the physically connected Prime do not immediately propagate to the Connectivity Kit. To reflect those changes in the Connectivity Kit, you need to right-click on the calculator's name in the 'Calculators' list and select 'Refresh' from the context menu. If you didn’t perform this step, you were working with the version stored in the Connectivity Kit, not the one on the Prime.

Once you perform a refresh and drag your application from the Connectivity Kit to the desktop, an hpappdir file will be created, ensuring that it contains everything. If you share this file online, anyone can install and use it without issues.

That said, if you insist on creating AVars variables in the code, you must refer to them in the same way everywhere, that is, also by using AVars. Otherwise, the program will not compile.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)