Shield text needs to show maximum value of 100

ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
Hello all

I have a problem with my bonus system and my shield attribute value

I have a game where if the player destroys all the ships on screen, I would like it to add 20 units to the shield that at 100% is the number 100 (displayed as text as have no good graphic effect to show shields).

If the ships go off screen they bomb the earth and the shield (100 units as shows as text) is depleted by 10 units per ship.

Now, I want it so, when the player successfully destroys all aliens, the game will add 20 units back onto the shield but I would only want to to stop and show 100 (i.e 100%).

I have an attribute called - 'Earth Shield' and it starts each fresh game as 100.

How do i get the earth shield text to only show a maximum of 100 if 20 units are always added to the earth shield?

I have it now say the earth shield is at 90, when the destroy all aliens bonus is add (20 units back) it shows 110? - need it to only show 100.

Oh if anyone has a good graphic effect that can show 100% (shield) then I would love to know.

Thanks everyone :)

It takes a Zombie to know a Zombie!!!

Comments

  • TheGabfatherTheGabfather Member Posts: 633
    Have a Rule that checks if your shield's value is >100, change it down to 100 :) you need only do this one time, no need to add it to all your Rules that increment your shield's value.
  • ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
    Ah it was so simple, why didn't i figure that out...doh

    Thanks Gabfather... :)

    It takes a Zombie to know a Zombie!!!

  • slowcutslowcut Member, PRO Posts: 164
    If you want lean code, use the "min" function in the expression editor:

    When condition is valid, change game.shield to min(game.shield+20,100).

    (The min Function returns the smaller one of two values)
  • ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
    If you want lean code, use the "min" function in the expression editor:

    When condition is valid, change game.shield to min(game.shield+20,100).

    (The min Function returns the smaller one of two values)
    Thanks Slowcut...anything to make the game work smoother and leaner. Thank you very much for your solution :)

    It takes a Zombie to know a Zombie!!!

  • ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
    If you want lean code, use the "min" function in the expression editor:

    When condition is valid, change game.shield to min(game.shield+20,100).

    (The min Function returns the smaller one of two values)
    Thanks Slowcut...anything to make the game work smoother and leaner. Thank you very much for your solution :)
    Slowcut or anyone :)

    How exactly would I enter this in Gamesalad? I've now added 10 - 100 GFX actors for the numbers as the shield goes up in steps of 10.

    When the shield goes to over 100 the 100 GFX I have assigned disappears as I have a rule for each of the ten numbers - if earth.shield is NOT 100 ( or 80 for say then 80 shield rule and all the same for the rest) then destroy actor.

    Now when I have a shield strength of say 80 and a bonus of 30 is added, the score should go to 100 again but gamesalad added the 30 to the 80...the shield then goes temporarily to 110 but this then of course makes my 100 graphic disappear as there is no GFX actor for anything above 100.

    How do I fix it so if 100 is the absolute maximum, gamesalad does calculate anything over 100.

    I'm ready to submit to itunes but need to fix this final bug!

    Thanks guys

    It takes a Zombie to know a Zombie!!!

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    If you want a maximum limit on an attribute just do this:

    Rule (assuming you have an Attribute named Strength):

    if strength is => 100

    change attribute strength to 100
  • slowcutslowcut Member, PRO Posts: 164
    @Zombiebrains if you use the method I mentioned above, GS will return the 100 if the other value is greater than 100.
    The min function will return the smaller of two values, so a min(80+30,100) will return 100. min(90+30,100) will return 100, etc
    Just implement this function in all your calculations and you won't get a value greater than 100...
  • slowcutslowcut Member, PRO Posts: 164
    @jamie_c if you do so you have to add a new rule and a new change attribute to you code.
    First you let the engine add values over a limit, then you let the engine check if this calculation has crossed the limit, and if so the engine has to correct the value to the limit...
    If you have lots of actors and lots of rules, this will affect the performance.
    So why not implement the limit in the first calculation and get rid of all following calculations?

    You can use the max function for a lower limit by the way...
    max(attribute-10,100) will return the greater value, so if you subtract from a value and your limit is again 100, no values smaller than 100 will be returned (that makes only sense if the attribute you want to subtract from is greater than the limit of 100)

    Both ways will seriously lighten your code...
    And that is always good (even in GS)
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    @slowcut, you're right. I didn't read the entire thread, just the most recent question. :)
  • ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
    @jamie_c if you do so you have to add a new rule and a new change attribute to you code.
    First you let the engine add values over a limit, then you let the engine check if this calculation has crossed the limit, and if so the engine has to correct the value to the limit...
    If you have lots of actors and lots of rules, this will affect the performance.
    So why not implement the limit in the first calculation and get rid of all following calculations?

    You can use the max function for a lower limit by the way...
    max(attribute-10,100) will return the greater value, so if you subtract from a value and your limit is again 100, no values smaller than 100 will be returned (that makes only sense if the attribute you want to subtract from is greater than the limit of 100)

    Both ways will seriously lighten your code...
    And that is always good (even in GS)
    Hi Slowcut

    Thanks for the reply.

    In my game I have an invisible actor on my scene.

    This has a set of rules where if the Earth Shield is 100 it will spawn in front of the invisible actor the actor '100'. If the shield is 50 it will spawn the actor '50'.

    Now each actor has a rule...example below.

    If Earth.shield is not 100 then destroy.

    I'm struggling to get my head around the min thing...sorry me being a noob and thick! :)

    How can I get your idea working in my scenario.?

    Sorry to pester you over this.

    It takes a Zombie to know a Zombie!!!

  • slowcutslowcut Member, PRO Posts: 164
    @Zombiebrains somewhere in your game there must be an actor to increase the Earthshield. I do not know where and how you do this, but you have to implement the min function in exact this rule.
    And if you do that your Earthshield will never be greater than 100...
  • ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
    I have a rule that if the you get to a certain score, say 1000 points it will reward 50 points towards the Earth Shields. All the additions to the aerate Shield are linked to point rewards...1000, 5000, 7500 right up to 500,000.

    I presume what your saying is that I need to add this MIN thing to that rule.

    Never used MIN so unsure how to enter it in my rules.?

    It takes a Zombie to know a Zombie!!!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2014
    The min() function is in the functions drop-down menu within the expression editor:

    image

    Replace the 'x' and 'y' values with values or expressions as needed, according to the suggestions made above in this thread.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • slowcutslowcut Member, PRO Posts: 164
    You can either select the "min" function from the pull down menu (like tatiang showed above) or you type it directly into the expression editor, but be sure to use the right syntax with the two brackets and the comma to separate the values.
    All math-functions from that pull-down-menu could be typed in directly.
    I prefer this, because it is faster and if you have a more complex expression, the editor becomes a very long window and you have to scroll back every time to implement a new function.

    @Zombiebrains you have to modify your earth shield rules

    At the point where you add the the values to the earth shield you modify the change attribute behavior:
    earthshield to "min(earthield+value,100)" (without the quotes and don't type the earthshiel attribute, you must select it from the drop down menu underneath the arrow button left to the "Insert function")
  • ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
    You can either select the "min" function from the pull down menu (like tatiang showed above) or you type it directly into the expression editor, but be sure to use the right syntax with the two brackets and the comma to separate the values.
    All math-functions from that pull-down-menu could be typed in directly.
    I prefer this, because it is faster and if you have a more complex expression, the editor becomes a very long window and you have to scroll back every time to implement a new function.

    @Zombiebrains you have to modify your earth shield rules

    At the point where you add the the values to the earth shield you modify the change attribute behavior:
    earthshield to "min(earthield+value,100)" (without the quotes and don't type the earthshiel attribute, you must select it from the drop down menu underneath the arrow button left to the "Insert function")
    Good morning Slowcut

    I've been a pleb! after all that effort, I had forgotten to add the reference back to the Earth.Shield before adding the +20,100.

    My expression was

    if score = 1000, - min(+20,100) instead of min(Earth.shield+20,100).

    Thank for your original comment as I just didn't read it properly.

    I've added that to all my points increaser rules and it worked a treat now! :)

    Thanks to you and the other great people in here with helping me with that...

    I can now get this submitted to the app store today.

    Happy bunny now :)

    It takes a Zombie to know a Zombie!!!

  • slowcutslowcut Member, PRO Posts: 164
    @Zombiebrains

    Good luck with your game
Sign In or Register to comment.