3
$\begingroup$

I am creating a Random Math Engine using the BGE and I am wondering how I can do mathematical operations between two properties. Example: "Property 1 + Property 2" and then it would output the answer in text when you hit "A". But I don't know how to add/subtract/multiply/divide properties together.

$\endgroup$
5
$\begingroup$

Adding, Subtracting, Multiplying, or Dividing properties can be done very easily - you simply need a third property, which you can assign the result to.

enter image description here

You can use logic like this to perform mathematical operations on any type of object. If you want to display the result as a text object, the easiest way is like this:

enter image description here

In this case, the result is stored as a "Text Game Property" - This is a special type of property for text objects, which will display the value as text in game.

$\endgroup$
  • $\begingroup$ I have the same problem but when I try the above my total property always stays at -1. I have checked and rechecked on spelling etc. I am unsure if there need to be special characters in the value input such as (A+B+C) or "A+B+C"? $\endgroup$ – Shawn Barfield Apr 20 '18 at 14:06
  • $\begingroup$ One thing that could be messing it up is spaces in the property name. For example, if you have two properties, "Object Health" and "Damage", and you try to do "Object Health-Damage," the space will mess it up into making blender think you're subtracting "Damage" from a non-existent property "Health." I'm not sure if that is your problem, but it is one I've run into a lot before. $\endgroup$ – X-27 wants to Reinstate Monica Apr 21 '18 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.