• 🏆 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!

[General] Retrieve Unit Type ID from a List Linked to an Integer

Status
Not open for further replies.
Level 39
Joined
Feb 27, 2007
Messages
5,023
JASS:
JASS:
globals
    integer array UnitIdsForYou[8][9]
    integer Gateway1 = 0
    integer Gateway2 = 2
    //etc.
    integer Gateway8 = 7
endglobals

set UnitIDsForYou[Gateway1][0] = 'hfoo'
set UnitIDsForYou[Gateway1][1] = 'hpea'
//etc.
set UnitIDsForYou[Gateway8][8] = 'u052'

GUI:
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set MaxGateways = 8
    • Set MaxUIDs = 9
    • -------- --------
    • Set GateWayNum = 0
    • Set UIDNum = 0
    • Set Index = GateWayNum*MaxGateways + UIDNum
    • Set UnitIDsForYou[Index] = Footman
    • -------- --------
    • Set GateWayNum = 0
    • Set UIDNum = 1
    • Set Index = GateWayNum*MaxGateways + UIDNum
    • Set UnitIDsForYou[Index] = Peasant
    • -------- --------
    • Set GateWayNum = 7
    • Set UIDNum = 8
    • Set Index = GateWayNum*MaxGateways + UIDNum
    • Set UnitIDsForYou[Index] = MegaSuperAwesomezard
Or you could use a Hashtable if you're not chill with vJASS or don't want to simulate 2-d arrays in GUI.
 
Last edited:
Level 13
Joined
Nov 7, 2014
Messages
571
JASS:
globals
    integer array UnitIdsForYou[8][9] // 8 * 9 = 72
    integer Gateway1 = 0
    integer Gateway2 = 1
    //etc.
    integer Gateway8 = 7
endglobals

JASS:
// UnitIdsForYou[8][9] // 8 * 9 = 72 // 0 .. 71
set MaxGateways = 8 // 0 .. 7
set MaxUIDs = 9 // 0 .. 8

set GatewayNum = 7 // Gateway8
set UIDNum = 8

set Index = GatewayNum*MaxGateways + UIDNum*MaxUIDs
set Index = 7*8 + 8*9 // 128 o.O?

I.e your formula is incorrect, should be:
JASS:
set Index = GatewayNum*MaxUIDs + UIDNum
set Index = 7 * 9 + 8 // 71
 
Status
Not open for further replies.
Top