• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

String to ability or item name

Status
Not open for further replies.
Level 6
Joined
Jan 16, 2013
Messages
68
Since I can't find a way to convert a string to an item or ability name in the GUI like I did with units I figured maybe you can do it in JASS.

The problem is I am completely inexperienced with JASS so that's why I am asking more experienced mappers.

How do I convert a string to the Name property of an ability and an item in JASS?
 
Have you tried:
http://wiki.thehelper.net/wc3/jass/common.j/GetObjectName
?

It takes the rawcode of an object and returns the name field in the object editor.

For example:
JASS:
local string s = GetObjectName('hfoo')
'hfoo' is the rawcode of a footman, so it would place the local string variable 's' would point to "Footman".

To find the rawcode of an object, open the object editor, find the object you're looking for, then press CTRL+D. All the rawcodes should be displayed. It'll be a 4-digit code. When entering it as input for GetObjectName, enclose the 4-digit code in single-quotes (as shown in the example above).
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
There is no function to get an ability or an item by its name, though they initially wanted to implement something for abilities:

Code:
constant native OrderId                     takes string  orderIdString     returns integer
constant native OrderId2String              takes integer orderId           returns string
constant native UnitId                      takes string  unitIdString      returns integer
constant native UnitId2String               takes integer unitId            returns string

// Not currently working correctly...
constant native AbilityId                   takes string  abilityIdString   returns integer
constant native AbilityId2String            takes integer abilityId         returns string

// Looks up the "name" field for any object (unit, item, ability)
constant native GetObjectName               takes integer objectId          returns string

Anyway, that would not be a conclusive relation. Multiple objects can share the same name. Since there is also no function to get all the items in the map, Maker suggests to manually assign the items to their names on map init.

Like:

  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set items[0] = Frost Orb
    • Set items[1] = Kelens Dagger of Escape
    • Set items[2] = Claws of Attack +15
    • Set items[3] = Crown of Kings +5
    • Set items[5] = Mask of Death
    • ...
    • -------- - --------
    • Spiel-Cache - Create a game cache from itemgc.w3v
    • Set itemgc = (Last created game cache)
    • For each (Integer A) from 0 to 5, do (Actions)
      • Loop - Actions
        • Custom script: call StoreInteger(udg_itemgc, "ids", GetObjectName(udg_items[bj_forLoopAIndex]), udg_items[bj_forLoopAIndex])
  • Events
    • Player - Player 1 (Red) types a chat message containing <Empty String> as Partially Matching
  • Conditions
  • Actions
    • Set s = (Entered chat string)
    • Custom script: set udg_item = GetStoredInteger(udg_itemgc, "ids", udg_s)
    • Item - Create item at (Center of (Playable map area))
Not everything is available in GUI, such as GetObjectName or the item-type type in GUI is actually an integer in jass but they had it separated, which is why you cannot select it in GUI's gamecache actions. Gamecache, is a storage with 2 string keys. I have proposed it here because arrays are numerically indexed (and only 0 to 8190) and hashtables also take 2 integer keys. There is the StringHash function but ofc that may return the same value for different strings since string is the potentially far bigger type.

item is an item-type variable, itemgc gamecache, items item-type with array, s string. In jass, you can see the variable you create in GUI are actually prefixed by udg_.

Also, better get some clue about hashtables and jass if you want to accomplish anything.
 
Status
Not open for further replies.
Top