• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Assign custom items/abilities to integers?

Status
Not open for further replies.
Level 3
Joined
Aug 30, 2006
Messages
22
Hello there,

is there any way to reliably assign your custom items to different integers (from 1 to X) each?

Is there a way to pick every item or ability type (maybe by their raw data string?) and assign them to a rising Integer?

I didn't post this into the Triggering section as i haven't found a basic way to do is and want to know if it's possible with GUI.

Cheers,
Darkstar
 
Level 3
Joined
Aug 30, 2006
Messages
22
This is for a save/load system and i'm trying to get around cataloging each new item and ability, because the map already has hundreds of them. So if i could store every different item type in a different Integer on variable X i could assign them at map initialization without further caring about it.

I don't know if i can pick apart the item types though. When i look at the raw data code, why is it sometimes I006 and sometimes I00X? Why does it switch between using letters and numbers?
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
I don't know if i can pick apart the item types though. When i look at the raw data code, why is it sometimes I006 and sometimes I00X? Why does it switch between using letters and numbers?
Raw code values are 32 bit unsigned integers. Since ASCII is used they are broken into 4 characters of 8 bits each. They are assembled in big-endian order.

JASS has special syntax for evaluating raw code tags. You can place one within single quotations and it will be automatically parsed as the appropriate integer value.
JASS:
integer RAWCODE_EXAMPLE = 'I00X'
Since they represent a sequence of bytes, there must always be 4 characters.
JASS:
// this is valid, it is 4 bytes
integer RAWCODE_EXAMPLE1 = 'I00X'
// this is not valid, it is 3 bytes so one too short
integer RAWCODE_EXAMPLE2 = '00X'
Since each byte is represented as an ASCII character for readability it means that the character '0' is not numeric 0 but rather 48. Use an ASCII table to evaluate the character values.

This also means that there exists a lot of strange but still valid raw code combinations.
JASS:
// this is valid
integer RAWCODE_EXAMPLE1 = '@@@@'
// this is valid
integer RAWCODE_EXAMPLE2 = '!!!!'
// this is valid
integer RAWCODE_EXAMPLE2 = '~~~~'
It is not possible to iterate through all existing object types because there is a possibility for 4,294,967,296 different raw code values. The only way it would be possible is if you have a native allowing you to lookup types from a list (like SC2 has) but sadly WC3 lacks such a native.

The problem has been solved in the past by using LUA macros supported by the JNGP editor extension. At compile time this can lookup existing objects from the object declarations and return their raw code values. You then use the macros to generate the appropriate JASS for hard-coding all object types into the system. The only problem with this is that the LUA extension broke a long time ago and was never fixed due to a lack of maintenance. I believe other people have been trying to add such functionality back but I am unsure if they were successful or not.

To prevent new items from breaking the save/load codes you will need to keep track of a "type list". This maps all object types to a static list index. Removing an object type would then invalidate the index rather than remove it so that all elements after it retain the same index. New types are then appended at the end of the list (new index). Without this list the index of types could drastically change after adding/removing types or even from build to build without types changing.

There is always the "lazy" approach. Since types are 32bit integers you can save them as a 32bit number in your code. This is bad for people manually writing out the code and open to exploitation (getting types not normally possible) however it is very easy to do. Since raw codes usually use human readable characters at most 4 save/load digits are needed per type, possibly less with some form of compression.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Why does it switch between using letters and numbers?

Because we count using these characters:
0123456789
The rawcodes use these characters:
☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&'()*+,-./0123456789:;<=>?@ACDEFGHIJKLNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂Ç
(a few might be different)

However, even though they do use the same ids of these characters, they are not able to read all of them.
In the object editor, they only make objects using 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
as far as I know.

You can read everything else you need to know in DSG's post.

About your problem, I heard of an item system that had to register all item types and save something for each individual item type in a hashtable.
Even though the actual goal is not the same, it still can help.
But as I cannot find that system any more, you should try using the rawcodes of the items itself.

The 4 digit rawcodes are often misunderstood for strings, however they are integers... they just use a different kind of character to show it and use more.

However, when you retrieve the item type of such items, you can use that item type to have as integer instead of making it lead to an integer.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
A few, ala the values after ~, which are completly dependant on your locale, and all before space, since these are unprintable characters, but since this site probably uses utf8, the codes represent these printable characters instead(10 for instance is new line in ASCII).

Also, rawcodes can also store 1 byte, like 'v'.

Just my two cents.
 
Status
Not open for further replies.
Top