Rawcodes

Back to lessons

Rawcodes

This will be a brief tutorial covering WC3 rawcodes. Consider the following code:

function test takes nothing returns nothing
    local integer i = 'A000'
endfunction


Looks strange, doesn’t it? How can we set an integer to characters?

The key is that WC3’s compiler changes any rawcode into a numeric equivalent. Let’s do a test to see what happens:

scope MagicNumbersDemo initializer test

    function test takes nothing returns nothing
    local integer i = 'A000'
    call BJDebugMsg("Number: " + I2S(i))
    endfunction

endscope


Result:



This is the unique id for the rawcode ‘A000’, and it is how this rawcode is represented internally. So, why do we care?

Consequences:



In GUI, we have some variable types called “Unit-Type” and “Item-Type” in which we can do comparisons to unit/item types in the object editor. These types do not actually exist. They are just integers, made to look more convenient in GUI. The Ability variable is another that is actually just an integer.

As a result, if we ever want to store something like the type of the ability being cast, or the type of the triggering unit, declare the variable as an integer. If you want to compare them, you can then use an integer comparison and check whether they are equal to a rawcode, which will be auto-converted into an integer.

Interesting Rawcode Details:



It turns out that rawcodes in WC3 actually have meanings. Specifically, the first letter does This does not apply for built-in objects, but does for any user-defined objects.

- First letter ‘A’ means it is an ability
- First letter ‘B’ means buff OR destructible
- First letter ‘R’ means upgrade
- First letter ‘I’ means item
- For units: a lowercase first letter means it is a unit
- For units: an uppercase first letter means it is a hero
- For units: the first letter represents the race of the unit (i.e. ‘h’ for human, ‘o’ for orc)
- Anything after the first letter has no meaning. It is just a unique identifier.
- There are some reserved rawcodes, like ‘HERO’ that should not be overwritten.


To review:

    - Anything that uses a rawcode is an integer, even if there is a separate type in GUI
    - Use an integer variable to store types of units/items/abilities/etc. if needed

Back to lessons