What is so special about structs?

Reaction score
341
Am i understanding structs wrong or something , arent they just like globals? except you have to create them every new function?

i made a simple trigger using structs.

JASS:
globals
    unit array hero[12]
endglobals

struct test
    integer str
    integer agi
    integer int   
    string name  
endstruct

function herostats takes unit whichUnit returns nothing
    local test data = test.create()
    local force p = GetForceOfPlayer(GetTriggerPlayer())
    set data.str = GetHeroStr(whichUnit, false)
    set data.int = GetHeroInt(whichUnit, false)
    set data.agi = GetHeroAgi(whichUnit, false)
    set data.name = GetUnitName(whichUnit)

    call ClearTextMessagesBJ( p )
    call DisplayTimedTextToForce( p, 160.00, data.name )
    call DisplayTimedTextToForce( p, 160.00, " ")
    call DisplayTimedTextToForce( p, 160.00, "|c00FF0000Strength : |r" + I2S(data.str) )
    call DisplayTimedTextToForce( p, 160.00, "|c0000E100Agility : |r" + I2S(data.agi) )
    call DisplayTimedTextToForce( p, 160.00, "|c000000FFIntellegence : |r" + I2S(data.int) )
endfunction



What else are structs supposed to do?
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
Andrewgusu said:
To put it simple, structs are parallel globals arrays with a nice indexing system. No game cache involved, whatsoever.

That's pretty much it :rolleyes:
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> Globals are not mui?

That statement doesn't hold in general.
Otherwise using structs wouldn't improve anything either...

> So structs are MUI no matter what?

Nonsense.


> I made a simple trigger using structs.

Well, that example would be better off without structs.
And, you're not removing the struct when done.
 
Reaction score
341
Thats what im saying , i couldve done it without structs , ive read adrewgosu's tutorial also , and im still confused on what is a good way to use them
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Thats what im saying , i couldve done it without structs , ive read adrewgosu's tutorial also , and im still confused on what is a good way to use them

When you start learning about Callback speed timers, and attaching data to various things (units, timers, etc), you'll find them very easy to use, compared to the speed of attaching each individual member of a struct one at a time. Attaching something is very easy if you're just attaching a number, simply because of arrays.

The fact that they're global arrays also makes them much faster than storing the values on the computer itself, and then having to get it back off the computer, or doing a loop of 8190 comparisons to find the correct data.

Structs are useful for attaching, and for dealing with multiple things at once. Instead of multiple functions returning a unit, another unit, an ability, and an integer, you can put all of these into one struct, and have one function return all of them.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Spells and/or systems/snippets that uses additional functions. Timer callbacks or trigger callbacks for example.
 
Reaction score
341
I mean like , direct examples , i always hear people using them for spells but i dont know what for

thanks for that example larcenist
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Say you got a DoT for example: with a struct attachment system such as HAIL you could attach your struct to the targetted unit and keep a struct member counting ticks. If the same unit were to be affected by the same DoT again, you could use GetData(GetSpellTargetUnit()) and see if the unit has a struct attached to it. If it has, you could reset the ticks and renew the duration or similar.
 

dannyboydude

Ultra Cool Member
Reaction score
33
i feel sorry for you TriggerHappy learning this stuff is realy confusing , i still havnt figured out about what to do with structs libraries , scope and whatnnot else

im realy confused in all this stuff but ... i have only realy seen structs in spells
 

Viikuna

No Marlo no game.
Reaction score
265
Structs are really cool.
In many cases you could just use global arrays instead of structs, but structs are a easier to use in some cases.

You can have structs inside structs and stuff like that.

like:
JASS:
set Omg.LoL.ey = 1.234

set Omg.asd.x = Omg.LoL.ey
 

Jedimindtrixxx

┻━┻ ︵ ¯\(ツ)/¯ ︵ ┻━┻
Reaction score
168
what are the periods used for in that statement?
 

Viikuna

No Marlo no game.
Reaction score
265
EDIT. oh ye, wait sec i post more code.


EDIT2. Here is some fast made example how to attach some Data to some Hero, it might be usefull in some map where you have some Heroes...

JASS:
struct Velocity
    real x
    real y
    real z
endstruct

struct Color
    integer red = 255
    integer green = 255
    integer blue = 255
    integer alpha = 255
endstruct

struct Heroes
    string n = "nuthing"
    Color C
    Velocity V
endstruct

function F takes nothing returns nothing
     local Heroes H = Heroes.create()
     local unit somehero // some brave hero unit
     set H.C = Color.create()
     set H.V = Velocity.create()
     // 
     set H.V.x = GetRandomReal(-100,100)
     //
     call SetUnitUserData(somehero,H)
endfunction
 

Viikuna

No Marlo no game.
Reaction score
265
Bumb + Edit ( I just changed those Color reals to integers )
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top