Does changing Nesting of rules have an effect...?

Two.ETwo.E Member Posts: 599

Hello,

Going through and re writing a few games from scratch again, I came across a "logic nesting" habit I do and wanted to clarify if another way is more efficient.

Here is an example. By placing a Touch Condition with other attributes conditions.

I notice that I have about 30-40 conditions I sometimes need to check so is it better to wait until a Touch is registered.

I am not sure I understand how GS works with scanning code,
I assume nesting all the rules in the Touch rule means they wont be scanning until touch is pressed. Or is it more efficient to have the other conditions be scanning and match, so that when the final condition (touch) is met, the response is quick.

My concern that I start nesting rules, I wont have 1000 of conditions being scanned all the time? It doesn't have to be just related to touch. Any attribute condition.

Thanks,

Comments

  • MentalDonkeyGamesMentalDonkeyGames Member Posts: 1,276

    I'm not an expert, but i would do it like you have on the second example. Check the other conditions when touch is pressed.

    It's like you said. It will only scan the conditions when touch is pressed. Otherwise it will be constantly checking if they are true.

    Mental Donkey Games
    Website - Facebook - Twitter

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2016

    @Two.E said:
    I am not sure I understand how GS works with scanning code.

    This version will only have to check each rule (and calculate the long complicated expression) if all the previous conditions are met, so for example if touch is not pressed then GS doesn't have to process the other conditions and calculate the long complicated expression . . . it doesn't go any further than the first condition.

    Rule - if touch is pressed
    --Rule If X is smaller than 200
    ----Rule if Y is larger than 120
    ------Rule if score is larger than 5000
    ---------Rule if numeric expression (long complicated expression) is . . .
    -----------Then do some action.

    . . . . . . . . . . . . .

    This second version will check all the conditions (and calculate the long complicated expression) on every code cycle, so that long complicated expression is having to be calculated 60 times a second, over and over again . . . even if touch is not pressed.

    Rule - if touch is pressed
    and If X is smaller than 200
    and if Y is larger than 120
    and if score is larger than 5000
    and if numeric expression (long complicated expression) is . . .
    Then do some action.

Sign In or Register to comment.