Help With a Category Counter!

  • Hello everyone. I'm trying to build an action that can, from a list of scenes (each one with a category="something" or "null" variable), know how many categories there are in the list, create new variables for every type of category and within those variables count how many of each category there are. I'll give you an example:

    FROM THE LIST:
    <scene name="0" category="null"/>
    <scene name="1" category="A"/>
    <scene name="2" category="B"/>
    <scene name="3" category="A"/>
    <scene name="4" category="A"/>
    <scene name="5" category="A"/>
    <scene name="6" category="C"/>
    <scene name="7" category="B"/>

    In the end the action would have to create these variables with these values (Note that I wish the action to create the variables without me having to tell it which categories there are, and that the order of the scenes is irrelevant):

    A="4" B="2" C="1"

    I've been trying to build it with a for action but so far I have been unsuccessful, ¿any ideas?

  • Try something like that.

  • Hi! I love little challenges like this so here is my take:


    Cheers,
    Hernán

  • Woooooow, I thank you both for taking the time to help me, I tried Sachagriffin's suggestion but I wasn't able to make it work, and also I was confused by the %4 argument, probably I should have jiggled it more. Hernan's reply works wonderfully and is an exquisite piece of code. I had given up on that, I was making it work but with a different scene arrangement:

    <scene name="0" category="A"/>
    <scene name="1" category="A"/>
    <scene name="2" category="A"/>
    <scene name="3" category="B"/>
    <scene name="4" category="B"/>
    <scene name="5" category="B"/>
    <scene name="6" category="C"/>
    <scene name="7" category="C"/>

    Which is not exactly what I wanted. Hernan, I don't wear a hat but if I did it would go take it off for you.

    Thanks!

  • Challenge accepted. We should have more of this brain trainings. I'm sure this would help us all being better or?
    If you don't want to know the categories than I propose very similar approach but storing the results and reading them later on.


    x: 1
    a: 4
    b: 2
    c: 1
    d: 2

  • Thank you for the kind words! I'm glad it helped.

    Upon seeing it now I realized that it could be more even more succinct, and to keep it DRY, by putting "scene[get(i)].category" in a variable. Like:

    Code
    for(set(i,0), i LT scene.count, inc(i),
        copy(current, scene[get(i)].category); 
        if(get(current), 
          inc(get(current));
        ,
          set(get(current), 1);
        );
      );


    I also like Umalo's suggestion to store them somewhere if you don't know them firsthand, but that really depends on the problem you're trying to solve.

    Cheers *thumbsup*

  • Thank you very much, guys, your suggestions have helped me a great deal. Now I'm facing a new dilemma and hopefully you'll still want to lend me a hand, I think I should have mentioned that what I'm after is no easy thing to achieve, I believe, but I'm still learning anyway.

    So I've used the basic code you gave me to generate automatically a container layer for each of the categories in the list, now I'm on a mission to fill those containers with layers pertaining to the scenes in each category. I actually think I have that done already:

    So this way I'm successfully (I think) putting each of the layers in their corresponding container. The issue here is that I would like the scene layers (buttons) to have an increasing Y-offset, so they're not all cramped up in one place, but this increase should depend on the category of the scene. This is the part where I don't know exactly how to make it work, I think I could use the

    Code
    inc(get(scene[get(i)].cat));
    		,
    			set(get(scene[get(i)].cat), 1);

    .

    part, replacing the 1 with the Y offset I want and then reading it and assigning it to each layer, but I have tried to do so unsuccessfully.

    Any (other) ideas?

    Alberto.

  • I decided to try a bit more to see if I could fix it myself and fortunately I did (still there's so much to work in), thank you very much everyone!

    I'll post the final results when I get it done.

    Alberto.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!