| 08-04-2007, 04:00 PM | #1 |
What are these things called structs. Are they like the new game cache or something? I've never had the need for handles/game cache/etc so I don't know what they're about either. |
| 08-04-2007, 04:36 PM | #2 |
Structs are parrallel arrays... Download JassNewGenPack and read the file "jassnewgenpack3d -> jasshelper -> jasshelpermanual" for more information on structs and all the other new features given by JassNewGenPack |
| 08-04-2007, 05:55 PM | #3 |
struct is not the new game cache... |
| 08-04-2007, 06:17 PM | #4 |
Structs just make storage methods safer and quicker. |
| 08-04-2007, 06:18 PM | #5 | |
Quote:
My simple definition of structs is like supervariables which you can define and configure as you need, to see an example of what can you do check is this code: JASS:struct Vector real x real y real z endstruct function showvector takes vector v returns string return "[" + R2S(v.x) + "; " + R2S(v.y) + "; " + R2S(v.z) + "]" endfunction function SumVector takes Vector v1, Vector v2 returns Vector local Vector v = Vector,create() set v.x = v1.x + v2.x set v.y = v1.y + v2.y set v.z = v1.z + v2.z return v endfunction function playwithvectors takes nothing returns nothing local Vector v = Vector.create() // allocates the variables local Vector v2 = SumVector(v, v) call DisplayTimedTextFromPlayer(Player(0), 0,0,5, showvector(v) ) call DisplayTimedTextFromPlayer(Player(0), 0,0,5, showvector(v2) ) call v.destroy() // free / clean the variables. call v2.destroy() endfunction And you can add functions to the structs, which are called methods. JASS:struct Vector real x real y real z method showvector takes nothing returns string return "[" + R2S(.x) + "; " + R2S(.y) + "; " + R2S(.z) + "]" // check how we can make reference to the data in the struct endmethod endstruct function SumVector takes Vector v1, Vector v2 returns Vector local Vector v = Vector,create() set v.x = v1.x + v2.x set v.y = v1.y + v2.y set v.z = v1.z + v2.z return v endfunction function playwithvectors takes nothing returns nothing local Vector v = Vector.create() // allocates the variables local Vector v2 = Vector.create() set v.x = 10 set v.y = 20 set v.z = -5 set v2 = SumVector(v, v) call DisplayTimedTextFromPlayer(Player(0), 0,0,5, v.showvector() ) // check how we call the method LOL!! call DisplayTimedTextFromPlayer(Player(0), 0,0,5, v2.showvector() ) call v.destroy() // free / clean the variables. call v2.destroy() endfunction In order to learn more, check Jass New Gen documentation. |
