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

[vJASS] Convert int to struct

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,337
Hi,

If I have an integer array, I can put any struct inside it.

Question is, how do I 'cast' that integer back into the struct it was?

e.g.

JASS:
local integer array foo
local Struct1 a = Struct1.create(...)
local Struct2 b = Struct2.create(...)
set foo[0] = a
set foo[1] = b

Now given foo[0], what do I apply to get back the instance "a"?

Well I think all I need is to invoke the actual integer array storing all instances of Struct1, and just return

JASS:
//this is the integer array keeping track of all instances of Struct1
return struct1Array[foo[0]]

But I have no idea how to access that array or call whatever function does it...
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
you most likely cant do this dynamically unless using something like typeId or something, you can achieve this statically(if you know that given struct instance will always appear in given index of array) by StructName(array[index])
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Realized the difficulty of that--it would have been an ugly mess of textmacros.

I don't think I'll need this feature anymore though, but I appreciate the helpful answers!
 
Status
Not open for further replies.
Top