Capping a value?

MoikMoik Member, PRO Posts: 257
edited July 2015 in Working with GS (PC)

TL;DR - How to make x=x+1 cap at 10?

I mis-expected what the "max" function would do, and when looking for alternatives the ceil seems to be about rounding and Constrain seems to be more of a post-process than the pre-process I'm looking for. Does one of the Functions take a value and insure a variable does not go past that boundary? Do I need to make "if x > 10 then x = 10" type clean-up commands at the end of my loops, or is there a single clean function which already does that?

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    Just place this condition in the rule that changes X to X+1:

    When X is < 10

  • MoikMoik Member, PRO Posts: 257

    @Socks Elegant, thank you.

  • ArmellineArmelline Member, PRO Posts: 5,351
  • MoikMoik Member, PRO Posts: 257

    @Armelline That could be more suitable. There's a lot going on with the actor. I'm probably doing the constraints Socks suggested wrong.

    @Socks Can constraints be broken out within a Rule, like a nested if/then/else? I only see the "When all are true" at the start. The button I'm attaching these behaviours to is the defacto "Go" button. If I add the X < 10 to the Whens at the beginning the button won't fire in some cases where it should. Not sure if my laptop is being finicky about not letting me drag and drop the Condition into the Do section, or if I should be able to.

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2015

    @Moik said:
    I'm probably doing the constraints Socks suggested wrong.

    I've not suggested using a Constrain behaviour (if that's what you mean) ?

    @Moik said:
    Socks Can constraints be broken out within a Rule, like a nested if/then/else?

    I don't know what 'broken out within a Rule' means, sorry. :|

    @Moik said:
    I only see the "When all are true" at the start. The button I'm attaching these behaviours to is the defacto "Go" button. If I add the X < 10 to the Whens at the beginning the button won't fire in some cases where it should. Not sure if my laptop is being finicky about not letting me drag and drop the Condition into the Do section, or if I should be able to.

    What ! :smiley: Drag a condition !? Lol, sorry, my brain is overheating from a very hot night in London . . . you can't drag conditions ! Conditions are what you place in a Rule, to decide when the rule is triggered.

    Examples of conditions would be . . . .

    When touch is pressed . . or
    When X=600 . . or
    When Game.Time > 100 . . or
    When A collides with B . . . and so on

    . . . . when the conditions are met then the rule can trigger, so if you only want to add 1 to X when X is less than 10, your Rule would look like this . . . .

    Rule: When X < 10
    --Then do some stuff !

    So, let's imagine the process by which 1 is added to X is when the hero collides with an enemy, the Rule would look like this . . .

    Rule: When [all] Actor Collides or Overlaps with Enemy and When X < 10
    --Then do some stuff !

    Hope that make sense.

  • MoikMoik Member, PRO Posts: 257

    @Socks
    re: constraints. I'm using it in the more common usage sense than the Behaviour sense. The "When X is < 10" part of your suggestion looked like a constraint to me; one of the things in the first section of a Rule.

    re: broken out within a rule. I guess "ELSEIF" is what I should be saying. Like, within my knowledge of GS, It goes 1) "check a thing is happening" -> 2) "do option A if A is true" -> 3) do option B if A is false". Like, if GS Rules follow the usual programming logic of IF, THEN, ELSE. I was wondering if it's possible, in the middle of the Do or Else section of a rule, start another set of "When X is happening" style setups.

    re: dragging conditions: The version of GS I'm on has stuff like Attribute, AutoRotation, Collision, Hibernate under a "Conditions" heading within the Behaviours tab list, which I drag from the Behaviours list into the Prototype of an actor to fill out the conditions used in their trigger. Dragging in the development sense rather than the gameplay sense.

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2015

    @Moik said:
    The "When X is < 10" part of your suggestion looked like a constraint to me; one of the things in the first section of a Rule.

    I see, I was confusing constraint with constrain. Yes, the 'When X < 10' would be one of the rule's conditions/constraints.

    @Moik said:
    Like, within my knowledge of GS, It goes "check a thing is happening" 2) "do option A if A is true" 3) do option B if A is false". Like, if GS Rules follow the usual programming logic of IF, THEN, ELSE. I was wondering >if it's possible, in the middle of the Do or Else section of a rule, start another set of >"When X is happening" style setups.

    I'm not quite sure what you are saying, but if you are asking can other rules with other conditions be placed within the Do/Else sections, then the answer is yes.

    @Moik said:
    re: dragging conditions: The version of GS I'm on has stuff like Attribute, AutoRotation, Collision, Hibernate under a "Conditions" heading within the Behaviours tab list, which I drag from the Behaviours list into the Prototype of an actor to fill out the conditions used in their trigger.

    I've never seen any of that ! I never got passed version 12.10, I'll assume that stuff was added after 12.10 ?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @Moik are you using GameSalad Creator in OS X or Windows? It sounds like you may be using the Windows version (this subforum is for Mac). What version are you using?

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

  • MoikMoik Member, PRO Posts: 257

    @tatiang Don't tell anybody, but I'm actually using the Windows version :(
    I ask my questions on the Mac because it gets faster responses and there's rarely a significant difference between the platforms.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited July 2015

    @Moik said:
    tatiang Don't tell anybody, but I'm actually using the Windows version :(
    I ask my questions on the Mac because it gets faster responses and there's rarely a significant difference between the platforms.

    Lol! Well, the only problem -- as you can see -- is that in this case the question you are asking and the correct answer are platform dependent.

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

Sign In or Register to comment.