Difference between revisions of "Math operations"

From GTAMods Wiki
Jump to navigation Jump to search
(Created page with 'From GTA III to Vice City Stories, these games support limited math operations through the use of opcodes in the SCM file. This language is unlike most programming languages …')
 
Line 1: Line 1:
From GTA III to Vice City Stories, these games support limited math operations through the use of opcodes in the [[SCM]] file. This language is unlike most programming languages so it may take a while to learn how to perform some math operations. [[Sanny Builder]] supports the use of some of the operations without the need to type in the opcode in front. On this page, these supported operations have underlines in the "Related opcodes" section.
+
From GTA III to Vice City Stories, these games support limited math operations through the use of [[List_of_opcodes|opcodes]] in the [[SCM]] file. This language is unlike most programming languages so it may take a while to learn how to perform some math operations. [[Sanny Builder]] supports the use of some of the operations without the need to type in the opcode in front. On this page, these supported operations have underlines in the "Related opcodes" section. All examples on this page uses Sanny Builder.
  
All math operations can be done either using integers only or floats only. Otherwise the result will not be comprehensible.
+
All math operations should be done either using integers only or floats only. Otherwise the result will not be comprehensible. When using opcodes, make sure your variable type is supported by the opcode. Opcodes that calculate using global variables explicitly shouldn't be using local variables and vice versa.
  
 
==Addition==
 
==Addition==
 
1 + 4 = 5
 
1 + 4 = 5
<source lang="scm">0@ = 1  // stores the number '''1''' into the local variable 0@
+
<source lang="scm">0@ = 1  // stores the number 1 into the local variable 0@
0@ += 4  // adds '''4''' to the variable 0@ that stored the number '''1''' and stores the new number '''5''' into the variable 0@</source>
+
0@ += 4  // adds 4 to the variable 0@, which stored the number 1</source>
<span style="color:blue">0@</span> now equals to 4.
+
<span style="color:blue">0@</span> now equals to 5.
  
 
===Related opcodes===
 
===Related opcodes===
Line 25: Line 25:
 
==Subtraction==
 
==Subtraction==
 
5.5 - 8.0 = -2.5
 
5.5 - 8.0 = -2.5
<source lang="scm">0@ = 5.5
+
<source lang="scm">0@ = 5.5 // stores the number 5.5 into the local variable 0@
0@ -= 8.0</source>
+
0@ -= 8.0 // subtracts 8.0 (remember, calculate either in integers only or floats only) to the variable 0@, which stored the number 5.5</source>
 
<span style="color:blue">0@</span> now equals to -2.5.
 
<span style="color:blue">0@</span> now equals to -2.5.
  
Line 46: Line 46:
 
<span style="color:blue">0@</span> * <span style="color:blue">1@</span> = 20, where <span style="color:blue">0@</span> equals 5 and <span style="color:blue">1@</span> equals 4
 
<span style="color:blue">0@</span> * <span style="color:blue">1@</span> = 20, where <span style="color:blue">0@</span> equals 5 and <span style="color:blue">1@</span> equals 4
 
<source lang="scm">var
 
<source lang="scm">var
0@ : integer
+
0@ : integer // declare variables as integers
 
1@: integer
 
1@: integer
 
end
 
end
 
0@ = 5
 
0@ = 5
 
1@ = 4
 
1@ = 4
1@ *= 0@</source>
+
1@ *= 0@  // multiply 1@ to 0@ and stores the result in 1@</source>
 
<span style="color:blue">1@</span> now equals to 20.
 
<span style="color:blue">1@</span> now equals to 20.
 +
 +
===Related opcodes===
 +
*{{hint|0010|G *&#61; I}}: global variable *&#61; integer
 +
*{{hint|0011|G *&#61; F}}: global variable *&#61; float
 +
*{{hint|0012|L *&#61; I}}: local variable *&#61; integer
 +
*{{hint|0013|L *&#61; F}}: local variable *&#61; float
 +
*{{hint|0068|G *&#61; G int}}: global variable integer *&#61; global variable integer
 +
*{{hint|0069|G *&#61; G flt}}: global variable float *&#61; global variable float
 +
*{{hint|006A|L *&#61; L int}}: local variable integer *&#61; local variable integer
 +
*{{hint|006B|L *&#61; L flt}}: local variable float *&#61; local variable float
 +
*{{hint|006C|L *&#61; G int}}: local variable integer *&#61; global variable integer
 +
*{{hint|006D|L *&#61; G flt}}: local variable float *&#61; global variable float
 +
*{{hint|006E|G *&#61; L int}}: global variable integer *&#61; local variable integer
 +
*{{hint|006F|G *&#61; L flt}}: global variable float *&#61; local variable float
  
 
==Division==
 
==Division==
Line 65: Line 79:
 
<span style="color:blue">$var</span> now equals to 6.0.
 
<span style="color:blue">$var</span> now equals to 6.0.
  
[[Category:Mission Scripting]]
+
===Related opcodes===
 +
*{{hint|0014|G /&#61; I}}: global variable /&#61; integer
 +
*{{hint|0015|G /&#61; F}}: global variable /&#61; float
 +
*{{hint|0016|L /&#61; I}}: local variable /&#61; integer
 +
*{{hint|0017|L /&#61; F}}: local variable /&#61; float
 +
*{{hint|0070|G /&#61; G int}}: global variable integer /&#61; global variable integer
 +
*{{hint|0071|G /&#61; G flt}}: global variable float /&#61; global variable float
 +
*{{hint|0072|L /&#61; L int}}: local variable integer /&#61; local variable integer
 +
*{{hint|0073|L /&#61; L flt}}: local variable float /&#61; local variable float
 +
*{{hint|0074|L /&#61; G int}}: local variable integer /&#61; global variable integer
 +
*{{hint|0075|L /&#61; G flt}}: local variable float /&#61; global variable float
 +
*{{hint|0076|G /&#61; L int}}: global variable integer /&#61; local variable integer
 +
*{{hint|0077|G /&#61; L flt}}: global variable float /&#61; local variable float
 +
 
 +
==Absolute value==
 +
| -2.0 | = 2.0
 +
<source lang="scm">0@ = -2.0
 +
0097: make 0@ absolute_float</source>
 +
<span style="color:blue">0@</span> now equals to 2.0
 +
 
 +
===Related opcodes===
 +
*0094: global variable integer
 +
*0095: local variable integer
 +
*0096: global variable float
 +
*0097: local variable float
 +
 
 +
==Sine and cosine==
 +
*Sine and cosine opcodes use degrees, not radians. They should be floats, not integers.
 +
 +
<source lang="scm">0@ = 30.0
 +
02F6: 0@ = sine 0@</source>
 +
<span style="color:blue">0@</span> now equals to 0.5
 +
 
 +
===Related opcodes===
 +
*02F6: sine
 +
*02F7: cosine
 +
*02F8: car's z angle sine
 +
*02F9: car's z angle cosine
 +
 
 +
[[Category:Mission_Scripting]][[Category:Math_OpCodes]]

Revision as of 19:12, 16 May 2010

From GTA III to Vice City Stories, these games support limited math operations through the use of opcodes in the SCM file. This language is unlike most programming languages so it may take a while to learn how to perform some math operations. Sanny Builder supports the use of some of the operations without the need to type in the opcode in front. On this page, these supported operations have underlines in the "Related opcodes" section. All examples on this page uses Sanny Builder.

All math operations should be done either using integers only or floats only. Otherwise the result will not be comprehensible. When using opcodes, make sure your variable type is supported by the opcode. Opcodes that calculate using global variables explicitly shouldn't be using local variables and vice versa.

Addition

1 + 4 = 5

0@ = 1  // stores the number 1 into the local variable 0@
0@ += 4  // adds 4 to the variable 0@, which stored the number 1

0@ now equals to 5.

Related opcodes

  • 0008: global variable += integer
  • 0009: global variable += float
  • 000A: local variable += integer
  • 000B: local variable += float
  • 0058: global variable integer += global variable integer
  • 0059: global variable float += global variable float
  • 005A: local variable integer += local variable integer
  • 005B: local variable float += local variable float
  • 005C: local variable integer += global variable integer
  • 005D: local variable float += global variable float
  • 005E: global variable integer += local variable integer
  • 005F: global variable float += local variable float

Subtraction

5.5 - 8.0 = -2.5

0@ = 5.5  // stores the number 5.5 into the local variable 0@
0@ -= 8.0  // subtracts 8.0 (remember, calculate either in integers only or floats only) to the variable 0@, which stored the number 5.5

0@ now equals to -2.5.

Related opcodes

  • 000C: global variable -= integer
  • 000D: global variable -= float
  • 000E: local variable -= integer
  • 000F: local variable -= float
  • 0060: global variable integer -= global variable integer
  • 0061: global variable float -= global variable float
  • 0062: local variable integer -= local variable integer
  • 0063: local variable float -= local variable float
  • 0064: local variable integer -= global variable integer
  • 0065: local variable float -= global variable float
  • 0066: global variable integer -= local variable integer
  • 0067: global variable float -= local variable float

Multiplication

0@ * 1@ = 20, where 0@ equals 5 and 1@ equals 4

var
0@ : integer  // declare variables as integers
1@: integer
end
0@ = 5
1@ = 4
1@ *= 0@  // multiply 1@ to 0@ and stores the result in 1@

1@ now equals to 20.

Related opcodes

  • 0010: global variable *= integer
  • 0011: global variable *= float
  • 0012: local variable *= integer
  • 0013: local variable *= float
  • 0068: global variable integer *= global variable integer
  • 0069: global variable float *= global variable float
  • 006A: local variable integer *= local variable integer
  • 006B: local variable float *= local variable float
  • 006C: local variable integer *= global variable integer
  • 006D: local variable float *= global variable float
  • 006E: global variable integer *= local variable integer
  • 006F: global variable float *= local variable float

Division

$var / 0@ = 6.0, where $var equals 13.8 and 1@ equals 2.3.

var
$var : float
0@: float
end
$var = 13.8
0@ = 2.3
$var /= 0@

$var now equals to 6.0.

Related opcodes

  • 0014: global variable /= integer
  • 0015: global variable /= float
  • 0016: local variable /= integer
  • 0017: local variable /= float
  • 0070: global variable integer /= global variable integer
  • 0071: global variable float /= global variable float
  • 0072: local variable integer /= local variable integer
  • 0073: local variable float /= local variable float
  • 0074: local variable integer /= global variable integer
  • 0075: local variable float /= global variable float
  • 0076: global variable integer /= local variable integer
  • 0077: global variable float /= local variable float

Absolute value

| -2.0 | = 2.0

0@ = -2.0
0097: make 0@ absolute_float

0@ now equals to 2.0

Related opcodes

  • 0094: global variable integer
  • 0095: local variable integer
  • 0096: global variable float
  • 0097: local variable float

Sine and cosine

  • Sine and cosine opcodes use degrees, not radians. They should be floats, not integers.
0@ = 30.0
02F6: 0@ = sine 0@

0@ now equals to 0.5

Related opcodes

  • 02F6: sine
  • 02F7: cosine
  • 02F8: car's z angle sine
  • 02F9: car's z angle cosine