Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

AND and OR with Computed Attribute values in a RULE

Hey guys. I was able to get some awesome help on my first question to the forum, and I hope to find an equally impressive answer to my next question.

I have four game variables set up for Front, Left, Right, and Back. Each stores a numeric value between 0 and 1000, but each is set differently at the start of the game: Front=800, Back=200, Left and Right both to 500.

I'm trying to create a rule that will allow me to allocate 10 units to one of these variables FROM the other three values.

My rule needs to do the following:

  1. Check for the appropriate keystroke.
  2. Check to make sure that variable isn't already at the maximum value of 1000.
  3. Check to make sure there's at least 10 units available among the other three values.

It seems that the RULE box has settings that ANY or ALL conditions must be met for the DO portion to occur, but I need to have both possibilities, like this:

If Key = i AND Front <= 980 AND (Left >10 OR Right >10 OR Back >10)

Because I can only specify ANY or ALL, the above doesn't seem possible. I then got the idea that I could make the above work if I slightly changed my thinking:

If Key = i AND Front <= 980 AND Left + Right + Back >10

This would allow the rule to work using all AND's, but now the problem is in how to check for the computed value of the Game Attributes Left, Right, and Back? It seems that it will only allow you to specify one attribute value in the Attribute IF block.

Is there a way I can do this? Thanks ahead of time to anyone who can steer me in the right direction.

Dave Weeks


  • RThurmanRThurman Posts: 2,818Member, Sous Chef, PRO
    edited December 2014

    Make a boolean attribute and then use the equation you came up with to set it. For example if I had a boolean attribute called "myBooleanAttribute" you could use a change attribute behavior:

    Change Attribute: myBooleanAttribute To: ((self.key=="i")and(self.front<980))and((self.left+self.right+self.back)>10)

    Then you can use a rule to check to see if 'myBooleanAttribute' is true or false.

    Note: There should be no spaces in the expression. The vanilla forum software seems to be inserting spaces.

  • dotorandotoran Posts: 8Member

    Yeah, that could work nicely, but with four shields surrounding the ship, the checks would need to be different for each shield, so I'd then need 4 booleans, right? That'd work as well. For this one, though, I decided to change up the game a bit and have it pull the same amount of power from all other shields, so a series of ANDs works fine now, because all three shields now have to have the minimum transferred power in order for it to work. I'll definitely keep your idea in mind for other issues. In fact, I can already see where your idea could solve a problem later on.



Sign In or Register to comment.