Variable variable names

Hi to everyone!

I'm the developer of the Facemaker software, which already supports Huawei, Amazfit and full Android watches.

Soon, it'll also support wearOS and hopefully, Garmin!

Here's my channel showing what you'll be able to do for Garmin very soon: (18) Facemaker - YouTube


I'm developing an intemediate layer between what Facemaker has and Monkey C.
Facemaker has something called Image Combos that I'd like to reproduce for Garmin. They are text widgets, but made with images, each with their own coordinates.

So for example, steps 12235, would translate to 5 images each with their coordinates, incremented by the width of each image of the Image Combo.
These images would be fetched from a single image array, 0 to 9.

This is the last widget I need to implement before I make a release and forever change the Garmin watchface world.

To make it easier for me, something like "variable variable names" would be awesome.
Storing variables on an array, with variable variable names and referencing them later would be great.

All images that compose the Image Combo will be stored in a variable, either with a library or an array.
So, accordidng to the steps (for example), I would update each of those dinamically created images on the onUpdate() method, first by applying a "format" method to make it 5 digits (if padding is selected on Facemaker) and then setting each digit to it's corresponding value.

This is very easy in javascript and other languages, but I haven't seen anything in the MonkeyC API that would allow me to store objects in arrays or libraries, but I guess that's normal when you're studying a new language, right? Creating a library with variable name to BitmapResource would be great.
Can someone show me how to do it, pretty please?


Thank you! I have a platoon of hundreds of watchface designers, from the Huawei framework, eager to provide new wonderful watchfaces for Garmin, so please, help me out.

I'm sure it'll revolutionize the Garmin watchface world.


Thank you,

Nuno

  • So, just to make it more clear, this is what I'm trying to achieve:




    Each of those "1" will be an independent "widget" by the Facemaker lexico (or an ImageResource by the MonkeyC lexico), and they all come from a single collection of images, 0 to 9.
    Storing them on a variable and being able to use them when updating the widget, this is what i want to do.
    An array of image objects, basically, that is addressed by index, 0 to 9.
    10 images that will feed the Image Combo widget.

    So, at each iteration of the onUpdate method, I'd update each one of those digits, fed from the ActivityMonitor.getInfo() and populating the digits from an array of ImageResource object. 

    Is this possible?

    Thank you :)


    Edit: if no one is able to help, I'll release this Facemaker version with support for Text widgets only, which would be a shame.
    The code I have developed is not optimized, because it adresses each image on the onUpdate method.

    I think this could be more optimized.

  • I don't understand your problem. You seem to be a programmer, you seem to know more or less what you want to achieve, and I see no problem achieving it in Monkey C (if i understand it correctly). Maybe if you shared the relevant part of your code we could help.

  • I don't seem to be a programmer, instead I have more than 20 years of experience with all kinds of languages.
    Your reply is almost insulting.

    I have developed software for major companies in all sectors and I'm proudlly nowadays a freelancer developer.

    But MonkeyC is a mistery to me, even consulting the API. Maybe because it is an amalgamation of several languages, so I bet you're not surprised by my confusion.
    The problem is I don't see a way of referencing a variable with a variable name.

    I understand your confusion, but follow this link to understand what a "variable variable name" means in the PHP context: PHP: Variable variables - Manual
    I
    I
     have used all kinds of languages, imperative and object based, but MonkeyC is still a mistery to me.


    What I want is simple.

    Imagine an array of images, retrievable from Rez.Drawables.

    How can I assign them to a variable in MonkeyC?
    Like, include them in an array and then use them programatically?

    Is this possible?

    The reason for the "variable variable name", is so I could declare an array of variables on the initialize() method and then I could use it on the onUpdate() method.

    Maybe I have a different background from yours, but what I want is really simple for those who are really into MonkeyC.
    Declare an array of objects on the initailize method, that I can use later.
    But this array is made up of objects, images I can use and display on the watchface.

    Thank you for your reply!

    Nuno

  • const DIGITS = {
      '1' => Rez.Strings.digit1,
      '2' => Rez.Strings.digit2,...
    } as Dictionary<Char, ResourceId>;

    Actually as it's digits from 0-9 it's even easier:

    const DIGITS = [
    Rez.Strings.digit0,

    Rez.Strings.digit1, ...
    ] as Array<ResourceId>;

    Probably in your case you'll have Rez.Drawables.digit1, ...

  • If I understand what you want, a common way to do this is with a custom font.  The images are is the png associated with the font.  When you draw "5" with that font for example, you get the image for "5".  Spacing is handled in the fnt file, as are colors by way of setColor that way.

    See https://developer.garmin.com/connect-iq/connect-iq-faq/how-do-i-use-custom-fonts/#howdoiusecustomfonts

  • I think you simply mean a variable which holds the name of another varialble. In my (very) old programming days, this was possible with dbase and Clipper compiler. They called it „macros“.

    As far as I can tell - this is not possible with monkey-C.

    About Clipper and dbase:
    As the product matured, it remained a DOS tool for many years, but added elements of the C programming language and Pascal programming language, as well as OOP, and the code-block data-type (hybridizing the concepts of dBase macros, or string-evaluation, and function pointers), to become far more powerful than the original.

  • Incorrect. I mean, you are correct, it can't be done as a string, but see me response above, 2 tricks to do it as an array or even dictionary 

  • Thank you all for the help!

    I ended up achieving what I wanted by defining an array of bitmaps on the initialize method:


    Then, on the onUpdate method, I fetch the steps from ActivityMonitor, pad it with zeros (if the designer chose to pad it) and then I fetch the correspondent image in a loop:



    This works perfectly:


    Thanks again for your help!