04132008, 06:44 PM  #1  
User from USSR

The Type integer
Integer type and rawcode as its instance
***Translation by ArchWorm*** Theory
Integer type in jass is a long signed int meaning each of them takes 32 bits: 31 for a number and one for a sign. In Jass integer can be presented in 8 (octimal), 10 (decimal), 16 (hexadecimal) and 256(ASCII) notation. I'll explain this briefly (if you are familiar with various notations you can go straight to the practics). In a decimal notation we increment greater order when the lesser one becomes more than or equal to 10(9+1=10). This applies to other notations as well, corrected that they "trigger" on their own bases. Meaning we change greater order after getting 8 in octimal and 16 in hexadecimal. By the way, we use only ten figures, so how to write figure ten, figure eleven and so on? In hexadecimal notation figures representing numbers greater than 9 are replaced with capital latin letters. So, "A" means "10", "B" means "11" et cetera(You can go further and advance it up to 36based notation). ASCII follows the same idea, but it uses chars' codes instead. For reference look into this table(taken from WEU documentation): If zero is placed before an integer number that number is written in octimal. (local integer i=012 // 10 in deciman) Hexadecimals use 0x in the same way. (local integer i=0x0f // 15 in dec)And if a number is marked by inverted commas you have rawcode ASCII notation. (local integer i='A' // 67 dec). If you want to translate number from one notation to another you can use WinCalc (switched to engineering mode). Translation to ASCII is simple as well: you can translate every "figure" using charcode table and afterwards write resulting codes as they follow. For example, 'A0a1': 'A' = 0x41, '0' = 0x30, 'a' = 0x61, '1' = 0x31, so 'A0a1' means 0x41306131 or 1093689649. Note that each rawcode is nothing but an integer, and therefore we can do any kind of mathematical operations with them. Look forward for examples. In Jass there is no possibility to present number in binary notation, but it is very important for us to know about it. As you might have understood, binary notation follows the same rules as octimal, decimal and hexadecimal: greater order (which is called here bit) appears when we get 2 or more in lesser: 1bin+1bin == 10bin (2dec). Now let's go back to our 32bit integer: Code:
0x 7 a 9 8 0 1 f 0 0111 1010 1001 1000 0000 0001 1111 0000 I shall notice, that the first bit is a sign bit, it determines whether number is positive (0) or negative (1). Positive numbers range from 0x00000000 (0dec) to 0x7fffffff (2147483647dec), negative range from 0xffffffff (1dec) to 0x80000000 (2147483648dec). When switching sign we have to change all bits' values to their opposites and have to add 1. In examples I will use single bytes so it is simplier to understand: Code:
0000 0001 // +1dec 1111 1110 // inv 1111 1111 // 1dec Now, although in JASS there are no bitwise shift operations, it is possible to mimic them with the help of division and multiplication. Code:
1000 1000 // *10bin (<<) 1 0001 0000 // /100bin (>>) 0000 0100 Bits that do not fit the result will be considered lost. Now, with the help of two shifts we can receive any bits we need: Code:
0110 1101 // *1000 0110 0000 // /100000 0000 0011 We caught some problems with the sign bit: Code:
0111 1100 // *1000 1110 0000 // 1110 0000bin  20dec 1110 0000 // but we can change value a bit +1000 0000 _____ _____ 1 0110 0000 We also can use separator bit to be sure that after our multiplication sign bit is equal to 0: Code:
0vv vvvv v  our values I shall add that multiplication / division on 10bin, 100bin, 1000bin is also left shift/right shift on 1, 2, 3 bits(2^1 == 2 dec == 10 bin; 2^2 == 4 dec == 100 bin; 2^3 == 8 dec == 1000 bin; 2^n == shift on n bits). That's all for theory, now I'll show examples of how to get it working. Practics
For example, there are some simple problems with their solution. Bonus gold
We have to add bonus gold depending on killer's stats (for example the unit has item or ability adding +50 % gold from creeps), and thus on a map there is simply a heap of creeps, each of them can drop completely different quantity of gold. There is a function creating texttag, it takes how much gold we add. Let's assume two variants, in the first 1 <=minGold <=maxGold <80000000, in the second 1 <=minGold <=MaxGold <=75Adding item
We have a map containing 60 types of custom heroes. When hero achieves level 25 there pops a specific artifact at its feet.Private unit data
It is necessary to memorize for ingame units how many ennemies and heroes they killed, and also on which side they battle (for example light or darkness). Presumably the unit cannot kill more 2000 units, cannot kill more than 500 heroes, and is either good or evil. There is presumably a lot of recipient units. The main condition of a problem  we cannot use cache nor variables nor arrays (only local scope). Solution of problems
Last edited by ADOLF : 05032009 at 09:33 PM. 

Sponsored Links  Login to hide this ad! 

04152008, 05:20 PM  #2 
Free Software Terrorist
Technical Director

We're going to need the English version before approving it.
__________________ 
04152008, 09:43 PM  #3  
BuranX

xD
__________________Quote:
but yes Vex is right... i also have problems to read software translated text =) + it's kind a math lesson. 

04162008, 12:35 PM  #4  
User from USSR

Quote:
ok, i shall try to ask familiar who can help with translation + If who that will want to help with translation  write to me... i shall be grateful) 

04162008, 10:46 PM  #5  
BuranX

Quote:
// search better at Russ forums for help ;) 

05052008, 06:09 PM  #6 
User from USSR

translation is updated  thank to ArchWorm)
__________________how now?) 
05082008, 06:03 AM  #7 
User
Join Date: Dec 2006
Posts: 253

I find this tutorial helpful, and I understand it. :) I am still a little confused on some areas, but I mainly read the tutorial fast. :P
Good job, +rep. I hope I'll find some uses of this. ;) 
05082008, 09:18 AM  #8 
Alcopops
Tools & Tutorials Moderator

Yes, I approve.
__________________ 
05082008, 11:51 AM  #9 
User from USSR

yes, thanks
__________________but imho this tutorial about jass... hmm misk: "Contains tutorials that do not fit into one of the above catagories" though it to solve to you) 
05082008, 03:52 PM  #10 
User

The text still seems somewhat awkward to me. Let's hope it's but my selfcriticism. Seeing it approved quite proves it.
__________________But tell me, have you understood anything around the problems? I hardly could make them readable so I fear they are good for nothing. 
01092009, 03:15 PM  #11 
User

local integer 0x0f // 15 in dec ? I think it should be local integer i=0x0f // 15 in dec
__________________ 
03032009, 05:34 AM  #12 
Probably AFK
Join Date: Feb 2009
Posts: 635

8symbol number systems are octal, not "octimal". Very helpful guide, though.
Dec(25) = Oct(31) Last edited by cosmicat : 03032009 at 05:37 AM. 
Thread Tools  Search this Thread 

