# Help: math with variables

 Randy I've been having some difficulty in the logic syntax for mathmatical operations. I get compile errors with the following examples:v100 = v100 + v101v100 = 100 - v100Apparently the program will not allow me to increment a variable by another variable or subtract a variable amount from a constant number. Am I right in this?Perhaps there is another way around what I want to do. I have a variable (v200) whose value is between 0 and 160. I am also placing an object (o5) on the screen and repositioning its x-coordinates based on v200 's value. Sounds easy, right? Well, here's the catch. I need to place it on the screen opposite the value of v200. So if v200=160, then the x-coordinate is 0,if v200=150, then the x-coordinate is 10,if v200=100, then the x-coordinate is 60 ...This would be easy if I could subtract the variable from 160, but as I mentioned earlier, the compile errors seems to suggest the logic has trouble with that.Any help would be much appreciated. Thanks. Robin_Gravel agi works differently.The problem I see looks like basic or qbasic language.In AGI you should write this:v100 += 100 // same like v100=v100+100 in basic.v100 -= 100 // same like v100=v100-100 in basic.Robin Gravel Randy That's what I'm saying though.It appears that addition and subtraction with variables only work to add or subtract a specific number from the variable.You can't add or subtract another variable, and you can't subtract the variable from a constant number.Given these limitations (because of the compile errors, I am assuming these are limitations, please correct me if I'm wrong) does anyone have any ideas how I can do what I need to do as mentioned in my first post? Joel if AGI Studio is not allowing you to sayv100 = v100 + v101;I can't imagine why not, although I would suggest trying things such asv100 += v101;oraddv(v100, v101);just to see if they work. Unfortunately, there is no way to subtract a variable from a constant as far as I can tell. You could assign 160 to a temporary variable and then subtract, like this:#define vTemp v201#define vXCoordinate v202vTemp = vXCoordinate;vXCoordinate = 160;vXCoordinate -= vTemp;Did you ever get that && problem fixed? Randy I don't have AGI Studio in front of me right now, but I was pretty sure I had tried to update a variable by adding different ones together and it didn't like it.I'll try again tonight, though.About the "&&", yes, I got it working. Thanks for asking. I went back and replaced the "||" with "&&" like I did so many times before and this time it worked. I don't know why it wouldn't have worked before but I was positive that was what I had done over and over again. Oh well, trials of creating and AGI game I guess.Sometimes when I create an OR statement it asks for brackets around the statement when they are already there. So I put another set (parentheses) around everything and then it compiles. Why does it need the second set?ex. if (v100==1 || v100==2) {error: put brackets around statementif ((v100==1 || v100==2)) {OK Joel It doesn't actually NEED them, I don't think, but it asks for them, anyway. I think this has to do with the way the logic resource stores OR commands. The statement:if (isset(f5) && isset(f6))looks like this when compiled:ff 07 05 07 06 ffwhere ff starts the if, 07 means isset, 05 tells it to look at flag 5, 07 = isset again, 06 tells it to look at flag 6, and ff ends the if. The statement:if (isset(f5) || isset(f6))looks like this, when compiled, however:ff fc 07 05 07 06 fc ffwhich is exactly the same as before, except the fc's surrounding the two tests, which tells AGI to OR them instead of ANDing them. That's just my guess as to why AGI Studio requires them. The real reason may have nothing to do with that. Joel Just noticed something you said. If you're trying to do this:v100 = v101 + v102;you can't do that I don't think. You'll have to do it like this:v100 = v101;v100 += v102; Andrew_Baker Exactly...This is why we describe AGI as being somewhat assembler-like with math.You can add two numbers of any kind, ie: v1+=v2 or v1+=100, but you can't say v1=v2+v3.You MUST say something like v1+=v2; v1+=v3;or v1=v2; v1+=v3;And by the way, AGI doesn't support math in conditional brackets. The values of conditionals must be determined BEFORE testing.This has been a public service announcement from a procrastinator.