Dr Super Good - Could you explain 1. in a more detailed way I'm not sure I understand all of it!
JASS:
if GetRandomInt(0,4) < 2 then
//your 40% chance code goes here
endif
Thats all there is to it...
native GetRandomInt takes integer lowBound,integer highBound returns integer
this returns a random integer between both bounds (inclusive).
Combined with a comparator test, you get a boolean.
This boolean is then used in flow control via an "if X then" statement.
Finally you can now run some code with a % chance.
The example should be 40% but that would only be the case if a good pesudo random generator is used in the WC3 engine. I have run tests in the past and the results did appear satasfactory for even distribution thus one can safly assume it is close enough to 40%.
And could someone point me a Tutorial about Integers(how they work and how to use them)?!
No one has bothered to write a tutorial on integers as they are so simple. You learn about them in math class (like at primary school).
All you need to know to use them is that there are 4 basic opperators in JASS that can combine them.
+ which adds them (same as normal math)
- which subtracts them (same as normal math)
/ which divides the number on the left by the number on the right
* which multiplies the two numbers together.
Rules of BODMAS apply (gah wish I knew the proper name for this). This means brackets and functions are solved first followed by division and multiplication folowed by addition and subtraction. Opperations at the same tier (like / and *) are solved from left to right.
Finally, integers are subsets of reals. This means where you can provide a real argument you can also give an integer argument instead and no syntax error will be raised. This also means that the opperators for reals can accept integers but will return a real. You will need to use the R2I native to get a real into an integer but be aware that it will truncate off the decimal data.
integer /*-+ integer = integer
real /*-+ integer = real
integer /*-+ real = real
real /*-+ real = real
Be aware that using the divide opperator (/) to "divide by 0" will cause a thread crash in the JASS interpreter. This means no further code below where the division by 0 occured will be run. The game however will not crash nor will any errors be displayed (unlike SC2) so this is a common cause of faults and failures.
Integers also have a range restriction
Dr Super Good said:
They are 32 bit signed (with two's compliment) giving them a range of possible values of -2^31 to +2^31-1.