How can I simplify my code for this star rating system?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hey Clickteam,

    I know there's an easier way to code what I'm trying to do, so I'm coming to the forums!

    I have two frames. The first frame is a level select screen with 8 buttons that represent 8 levels to choose. The second frame is the game.

    I created an active called "Stars" that looks like 3 faded stars. It's duplicated 8 times and are placed on each level button. I also animated the "Stars" active so when it's direction is to the right, it's 3 faded stars. When it's direction is down, the first star is lit, when it's direction is left, two stars are lit etc... It's a star rating for how good the player did in the game frame.

    I also spread value 0 in the "Stars" active.

    In the game frame, when a player completes a level in under 10 seconds they get three stars! Between 11-20 seconds, two stars, and over 20 seconds only 1 star. I created a global value called "Star_Counter" which sets the value to how many stars they achieved.

    What I'm trying to do is then set the "Stars" active animation on the level select screen to how many stars they achieved on the game frame. Right now I'm hard coding it like this:

    "Stars" Id=0 + "Star_Counter"=2 ------- Set "Stars" direction to down.

    It works this way but I have to do this for every single level. I know there is a better way but I don't know how. I'm sorry for not including a MFA, I'm at work. I can upload one tonight if my explanation is hard to follow. Thanks Clickers! :)

  • I'm working on something very similar using 3 star system.
    Right now I'm using INI object to set and store game progress.
    At the end of level I have a condition that checks the progress and assigns stars. For 1 star I set the active star direction to 8, 2 star to 16, 3 star to 24. Then save to ini,
    In the menu, I read the INI and set the direction. "SetDirection to groupitemvalue("INI", "lesson",one"). The "INI" value is set to 8, or 16, or24, which are direction numbers.

    This is my way of doing, but it may change.

    Check out my game!
    Please login to see this link.

  • Create an array or list where you store each level's star rating. For an Array, store the star rating for level 0 in the first X position of your array. In a List, you would store the level rating per line, ut make sure the level number corresponds to the List line number. This means level 0 would be stored on Line 0, level 1 would be stored on line 1, etc. I would store 0 stars (all faded star graphic) as 0, 1 star as 1, etc.

    Then the two options I can think of:

    1. Change it so your stars are actually frames of animation. So frame 0 (the first frame) is all fades stars, frame 1 is 1 star filled and 2 stars faded, frame 2 is 2 stars filled and one star faded, etc. Then you would create your stars at runtime on each button and set their animation frame to whatever value you stored in the array/list. The simplest way to do this would be with a loop where you create the stars and set their frame based on the loop's index.

    2. keep using directions, but you want to make the stars increase going counterclockwise on the direction wheel. This would make each direction a multiple of 8 (since direction left is 0, direction up is 8, etc...) and you can simply set the direction to your stored star rating in the array/list multiplied by 8.

    Please login to see this link.

Participate now!

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