Is it possible to write inside of the rule's "when" statement?
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
-
tatiang Posts: 11,949
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
-
RThurman Posts: 2,880
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
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
Hey @Socks, thank you on your fast reply!
This is exactly what i am trying to avoid
And this is what i am searching for
@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!
You're welcome!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@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
Can you please tell me where did you learn lua logical operations?
Probably https://www.lua.org/pil/3.3.html
You are welcome.
Exactly!
@Manto @RThurman Wow, awesome informations! Thank you guys a lot! This is the best community ever!!
You are welcome!
But I gotta admit that I would personally use the method @Socks suggested.
This is the GameSalad way of doing what you want. Why won't that work for you?