| 11-02-2002, 01:27 PM | #1 |
I found a way to cast variables of type 'handle' to more specified variable types. Imagine you only want to have ONE variable. Let it be an array of handles. But you can't do anything with handles, right? WRONG! You can cast handles this way: Write a cast function that looks like this: Code:
function Unit takes handle h returns unit
return h
endfunctionCode:
local handle h=GroupPickRandomUnit(GetUnitsOfPlayerAll(Player(0)))
local handle g=Player(0)
call KillUnit(Unit(h))You can also call KillUnit(Unit(g)). Java would throw an exception here, C++ programs would stop running, JASS just does nothing. And why should you use it? For example: You can now hold your dialogs and your dialog buttons in ONE SINGLE ARRAY of handles. w00t. :D :D :D:sun: |
| 11-02-2002, 02:09 PM | #2 |
Sounds very intresting. But who REALLY hates variables this much to goto this much effort... Superiki nice work. This handle method can add easy incorporation of tutorial and function maps into a users map but Can you create a Handle Variable Type into the variable window I don't remember it being there. |
| 11-02-2002, 03:37 PM | #3 |
well its also yet another way to stop newby from takin your map without protection cause if you only have 1 variable it would be even harder to telll what each thing does |
| 11-02-2002, 06:52 PM | #4 |
Hell yes, that kicks ***! That's the solution to the dialog problem right there... MUAHAHAHAHAHAHA |
| 11-02-2002, 07:18 PM | #5 |
DA: Aparently you didn't notice there is no variable type called Handle in the var window :/ and it doesn't solve jack shit its the same work except instead of 2 variables for all your dialogs and Dialog Buttons (As seen iN Dialog Test III) You now have 1 variable. Its not like its structs and what not. |
| 11-02-2002, 07:27 PM | #6 |
its relitively simple to add a variable of type handle to the WE, in fact you could create new variable called MyFavoriteVariableType and use that, but thats a bit overboard :D |
| 11-02-2002, 10:49 PM | #7 |
CBWhiz I realize that but if somebody has to download a patch to view/edit your map when your trying to save on variable types cuz your dang lazy and want to use 1 array instead of a WHOLE 2 viarables array (given by the example of Superiki), then you sir are the devil and need quick and painful castration. |
| 11-04-2002, 02:55 AM | #8 |
weadder: just a suggestion, I wouldnt do that to stop map stealing or to save a variable, but as a conversion method... I'm now trying do a conversion with a unittype > string, but it doenst work :( Code:
function StringIt takes handle h returns string
return h //I get invalid type for specified operator here
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
local handle d
set d = ConvertUnitType(19)
call DisplayTextToForce( GetPlayersAll(), StringIt(d) )
endfunctionBasicly this is to find out if a unittype variable is really a string, and if it is, try to make functions that go <> between those vars :( Am I making any errors? |
| 11-04-2002, 06:16 AM | #9 |
You can not cast a handle to a string. You can just cast a handle to something that extends handle or widget (coz widget extends handle). Look in the common.j to see what extends handle. |
| 11-04-2002, 04:36 PM | #10 |
Hmm I should have checked that :D Thanks anyway! |
| 11-04-2002, 06:15 PM | #11 |
So handles are like variables that can be converted to many different things, aka integer. Am I right in thinking. I will look at common.j when I get home. Awesome job SuperIKI :D |
| 01-18-2003, 12:49 AM | #12 |
so theres no way to make 1 super array? i was thinking i could use Weaddars 2-d array method and have like my first line strings, then integers, then units and so forth too bad |
| 01-18-2003, 06:16 AM | #13 |
You guys know whats the coolest part about this? This will actually let us make data structures that work for anything! Stacks queues, etc, someone can now publish a set of trigger utilities to include data structures that can accept any type of data. You can even create a binary tree using an array provided you are insane enough to desire one, i guess someone who was doing some serious ai work could now use this casting method to make his own tree more versitile. Anywho very good work! Anyone up for attempting hash table? lol. Btw, when you print out a handle, does it print as an integer? Maybe if you cast it to an integer then you can manipulate it ;) And that gets us into all sorts of interesting trouble, hehe. Thanks for this discovery Super Iki, now lets see what we can do with it.... FM_TertiaryEye |
| 01-18-2003, 06:47 AM | #14 |
I would actually classify this as a bug, though you could use it in this way as a feature. For example you can also do this which never makes any sense: Code:
function foo takes unit someUnit returns trigger
return someUnit
endfunctionI actually already wrote some datastructure libs for some testing stuff (nothing complex, just link lists, stacks, queues) -- well not really, just using arrays to fake them. But there will never be a nice way to do them in JASS because you can not declare first class pointers. In other words, you can't say make an array and pass the reference to that array around. Thus if you want to make access functions to your datastructure, like push() and pop() for a stack, you have to write one set of functions for every one of your datastructure instances. The way I "get around" this is by using a preprocessor that does this automatically for me (e.g., I write "stack1->push(myUnit)", the preprocessor converts it to "stack1Push(myUnit)" or something like that). Though its a nice idea, unless someone figures out some hidden "feature" in JASS that can be used be used as a pointer to a JASS variable (handles are pointers, but they can only point to in game datastructures, not JASS variables), it is provable that arbitrary composable types (types containing other types) are not possible. magnus P.S. This thread is pretty old isn't it? |
| 01-18-2003, 08:31 AM | #15 |
Hey mangus (or anyone else), do you know of a jass definition file anywhere in WC3, that allows you to change what the language accepts a little? If such a thing exists it might be our missing link. Another task that im sure someone knows is how to add a "handle" type to the variable editor? Anyone have any idea? Btw, i saw your jass site, great reference! Thanks. FM_TertiaryEye |
