Is it possible to write inside of the rule's "when" statement?

RedCubeGamesRedCubeGames Member Posts: 37
edited July 2016 in Working with GS (Mac)

Hello best community :# ! If you could help me with this one, that would be perfect and awesome!

I am interested is it possible to do this:
--- Rule - When - game.attribut = 1,3,5,8,14,15,16,25,29 - change image

I am trying to avoid doing this :
--- Rule - When - game.attribut = 1 - change image
--- Rule - When - game.attribut = 3 - change image
--- Rule - When - game.attribut = 5 - change image
--- Rule - When - game.attribut = 8 - change image
--- Rule - When - game.attribut = 14 - change image
--- Rule - When - game.attribut = 15 - change image
--- Rule - When - game.attribut = 16 - change image
--- Rule - When - game.attribut = 25 - change image
--- Rule - When - game.attribut = 29 - change image

NOTE: change image action is just for example.

If somebody knows how to achieve what i am looking for or is it even possible, that would be just amazing! :# Thank you in advance!

Best Answers

  • tatiangtatiang Posts: 11,949
    edited July 2016 Accepted Answer

    Rule - When - game.attribut = 1,3,5,8,14,15,16,25,29 - change image

    You could add the values to a table and do a tableSearch for game.attribut. Or...

    Create a text attribute called game.numbers with the value "#1#3#5#8#14#15#16#25#29". Then use the text contains condition to see if game.numbers contains "#"..game.attribut.

    The "#" symbol is there to prevent incorrect results when game.attribut is a single digit like 3 and game.numbers contains 35, for example, which would otherwise be a match.

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

  • RThurmanRThurman Posts: 2,880
    Accepted Answer

    I suppose you could also use the lua logical operators like this:
    ( self.attribut ==1)or( self.attribut ==3)or( self.attribut ==5)or( self.attribut ==8)or( self.attribut ==14)or( self.attribut ==15)or( self.attribut ==16)or( self.attribut ==25)or( self.attribut ==29)

    Here is an example.

Answers

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

    @RedCubeGames said:
    I am interested is it possible to do this:
    --- Rule - When - game.attribut = 1,3,5,8,14,15,16,25,29 - change image

    You can add as many conditions as you like to a rule, like this . . .

    Don't forget to change 'All' to 'Any' as you want your rule triggered by any of the listed values.

    I also bet their is some clever Lua-magic way to do it with a single expression . . . @Armelline @RThurman @Hopscotch

  • RedCubeGamesRedCubeGames Member Posts: 37
    edited July 2016

    Hey @Socks, thank you on your fast reply!

    You can add as many conditions as you like to a rule, like this . . .

    Don't forget to change 'All' to 'Any' as you want your rule triggered by any of the listed values.

    This is exactly what i am trying to avoid :#

    I also bet their is some clever Lua-magic way to do it with a single expression . . . @Armelline @Hopscotch

    And this is what i am searching for :smiley: :smiley: :smiley:

  • RedCubeGamesRedCubeGames Member Posts: 37

    @tatiang my pro membership just expired so i can't test the first version with tableSearch function (to see is it what i am looking for), but the second version with the text attribute works like a charm! Thank you very very much! :#

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

    You're welcome!

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

  • RedCubeGamesRedCubeGames Member Posts: 37

    @RThurman that is even better solution for my case! It is perfect, especially because you attached the demo project! Thank you so so so much :smiley: :smiley:
    Can you please tell me where did you learn lua logical operations?

  • MantoManto Member Posts: 796
    edited July 2016

    @RedCubeGames said:
    Can you please tell me where did you learn lua logical operations?

    Probably https://www.lua.org/pil/3.3.html :smile:

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @RedCubeGames said:
    @RThurman that is even better solution for my case! It is perfect, especially because you attached the demo project! Thank you so so so much :smiley: :smiley:

    You are welcome.

    @Manto said:

    @RedCubeGames said:
    Can you please tell me where did you learn lua logical operations?

    Probably https://www.lua.org/pil/3.3.html :smile:

    Exactly!

  • RedCubeGamesRedCubeGames Member Posts: 37

    @Manto @RThurman Wow, awesome informations! Thank you guys a lot! This is the best community ever!! :# :#

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    You are welcome!

    But I gotta admit that I would personally use the method @Socks suggested.

    @Socks said:

    You can add as many conditions as you like to a rule, like this . . .

    Don't forget to change 'All' to 'Any' as you want your rule triggered by any of the listed values.

    This is the GameSalad way of doing what you want. Why won't that work for you?

Sign In or Register to comment.