• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

hashtable parrent issued order, value unit type?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I want to store the order "humanbarracks" in a hash, and then be able to load by using issued order the unit type.

Not sure if this is wrong.
JASS:
call SaveInteger(hash, S2I("humanbarracks"),0,'hbar')
JASS:
i = LoadInteger(hash, GetIssuedOrderId(), 0)
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
S2I converts a number string to integer, integer i = S2I("521")
You need to use other order function that converts an order to integer, String2OrderIdBJ("humanbarracks")
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
StringHash may work too, but Ceday's solution is a lot, lot, lot better, because every order has fixed id, and the game can give it to you if you give it a string, meanwhile StringHash is just assed function with a chance of colliding
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
S2I converts a number string to integer, integer i = S2I("521")
You need to use other order function that converts an order to integer, String2OrderIdBJ("humanbarracks")

This is wrong, not sure exactly why, but i Load 0 instead of the unit type.

JASS:
set i = LoadInteger(hash, GetIssuedOrderId(), 0)

call SaveInteger(hash, OrderId("humanbarracks"),0,'hbar')

and if it can't find a match it will return 0 right? Debug states this statement is correct.
 
Last edited:
Level 12
Joined
Feb 22, 2010
Messages
1,115
No it is not wrong, I told you to use BJ function but you tried to be cool and didn't use it.You can look into BJ function for more details.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,217
Just to round off with the reason why the BJ was used...
JASS:
function String2OrderIdBJ takes string orderIdString returns integer
    local integer orderId
    set orderId = OrderId(orderIdString)
    if (orderId != 0) then
        return orderId
    endif
    set orderId = UnitId(orderIdString)
    if (orderId != 0) then
        return orderId
    endif
    return 0
endfunction
There are two separate natives used to convert order strings into order id numbers. In this case it must be using the native "UnitId" instead of "OrderId". As such it should be possible to inline with "UnitId" for better performance.
 
Status
Not open for further replies.
Top