Vjass

SFilip

Gone but not forgotten
Reaction score
634
If you have experience with Jass then you probably know that every handle type has to be created. For example:
local group g = CreateGroup()
Without creategroup you couldn't access this variable because it's empty - pointing nowhere actually.
Structs work in a similar way - just defining a struct does nothing, once you do a create you have access to it's members. Don't forget to destroy though, as you have a limit on the number of created structs.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
This is just an example but.....how come it can declare a [POINT] as a type?

It doesn't really declare a new type, instead JassHelper does some transformation on the code and turn it to "normal" jass. The jass generated is very hard to work with, you can say that structs of vJass is just synthetic sugar but it's a very sweet sugar :)

Your code will transformed to something like this:

JASS:
globals
    integer v__struct_point_number = 0
    integer v__struct_point_garbage = 0
    integer array v__struct_point_recycle
   
    real array v__struct_member_x
    real array v__struct_member_y
endglobals

function v__struct_point_method_create takes nothing returns integer
    if v__struct_point_garbage > 0 then
         set v__struct_point_garbage = v__struct_point_garbage - 1
         return v__struct_point_recycle[v__struct_point_garbage]
    endif
    set v__struct_point_number = v__struct_point_number + 1
    // Do initial initializing of struct members, your code had none
    // set v__struct_member_x[v__struct_point_number] = -1.2
    return v__struct_point_number
endfunction

function v__struct_point_method_destroy integer struct nothing returns nothing
    set v__struct_point_recycle[v__struct_point_garbage] = struct
    set v__struct_point_garbage = v__struct_point_garbage + 1
endfunction

function somefunc takes nothing returns nothing
local integer c = v__struct_point_method_create()
set v__struct_member_x[c] = GetUnitX(GetTriggerUnit())
set v__struct_member_y[c] = GetUnitY(GetTriggerUnit())
// hey, you forgot to destroy 
endfunction


Then we have private/public/static/error checking/ect that complicates stuff but the final result is always normal, but hard to work with, jass.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
cant understand...phrex's code...cant even understand 1 line
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
?

It's just a bunch of global arrays. Plus, vJass makes an Allocate and Destroy function for each 'struct'. It's really simple stuff... I could write a struct myself, but vJass does it for us, and we get to use struct and endstruct. YAY!
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
JASS:
    set v__struct_point_recycle[v__struct_point_garbage] = struct

Omg? integer = struct?
 

Tom Jones

N/A
Reaction score
437
Structs are nothing more than global variable arrays in disguise. When the preprocessor finds a struct declaration, it'll create a array for each declared variable inside the struct. Variables you declare inside a struct is called members. It'll also create (at least) two functions, one for creating a unique number for the index of the arrays associated with the struct (Remember that members of a struct is in fact arrays) and one for reallocating the arrays associated with the struct. A practical example of a struct declaration:
JASS:
struct data //When the preprocessor meets the declaration, it'll create a function called s__data__allocate and s__data__destroy
    unit u //When the preprocessor meets this member, it'll create a array called s__data__u
    unit v //When the preprocessor meets this member, it'll create a array called s__data__v
endstruct
Notice how the preprocessor uses the struct and members name as suffix for the arrays. Now when we use a struct we simply declare a local variable of the type of struct we want:
JASS:
local data s
If you think of a struct as a handle, just as unit, force, group, and timer are handles, it's easy to see why we declare it the way we do. Firstly we declare that it's a local variable. Next we declare that the type of the variable is data. Next we declare a name for the variable. Now we should get a unique number for this instance of the data struct, and we do this by using the function mentioned earlier, that creates a unique number. The function is actually also a member of the struct, and all members of a struct is accessed by the name of the struct variable, followed by a dot:
JASS:
local data s = data.create() //Since the variable s isn't declared yet, we're forced to use the type of the struct instead of the actual struct variable
We now have a unique number for this instance of the struct, and can now use the data variable s. Let's assign some units to the struct:
JASS:
local data s = data.create()
set s.u = CreateUnit(Player(0),'hfoo',0,0,0)
set s.v = CreateUnit(Player(0),'hkni',0,0,0)
set s.d = CreateUnit(Player(0),'hpea',0,0,0) //This will cause a syntax error, because d isn't a member of the data struct.
Now what the preprocessor is actually doing, is replacing the instances of s.u and s.v with the name of respective arrays, and using s as index. Neat isn't it?
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Code:
struct [B]data[/B] //When the preprocessor meets the declaration, it'll create a function called s__data__allocate and s__data__destroy  
unit u //When the preprocessor meets this member, it'll create a array called s__data__u  
unit v //When the preprocessor meets this member, it'll create a array called s__data__v 
endstruct

local [B]data[/B] [U]s[/U] = [B]data[/B].create() 
set [U]s[/U].u = CreateUnit(Player(0),'hfoo',0,0,0) 
set [U]s[/U].v = CreateUnit(Player(0),'hkni',0,0,0) 
set [U]s[/U].d = CreateUnit(Player(0),'hpea',0,0,0) //This will cause a syntax error, because d isn't a member of the data struct.

and is it we only can struct once per trigger? and also scope and library
is all the underlined and the bolded word needed to be same?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
1. No, if I understood you correctly. Did you mean that you can use a struct only once per trigger? If so, then no, because I think that you can use it multiple times.

2. Yeaaaa! Totally dude! :D

Sorry, I was listening to Party like a rockstar atm. :p
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>Did you mean that you can use a struct only once per trigger?
no...=.= i am asking...aw i will take an example and show u :
JASS:
struct data
real x
real y
endstruct

function ... takes....
actions....
endfunction....

struct anotherData
real a
real b 
endstruct

function otherfunction takes....
endfunction


can i do this??

>>Yeaaaa! Totally dude!
dude...whic question are u answerinG?
 

Tom Jones

N/A
Reaction score
437
You can make as many struct declarations as you want, with any name you like. You can also declare struct variables of the same struct type multiple times, as long as the variable name isn't the same:
JASS:
struct ABCD
    unit u
endstruct

struct someRandomNameForAStruct
    unit u
    unit v
endstruct

struct data
    string txt
endstruct

function ...
    local ABCD s1 = ABCD.create()
    local ABCD s2 = ABCD.create()
    local someRandomNameForAStruct s3 = someRandomNameForAStruct.create()
    local data whatever = data.create()
    local unit u = GetTriggerUnit()
    local unit v = GetSpellTargetUnit()
    
    set s1.u = u
    set s2.u = v
    set s3.u = u
    set s3.v = v
    set whatever.txt = "hey"
    set u = null
    set v = null
endfunction
Makes sense? data and s is simply the names I use for the name of the structs, and the name of a struct variables.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
So....As a conclusion...
JASS:
struct LoL
unit x
endstruct

In this line...LoL is declared as a [TYPE]

JASS:
local LoL afg = LoL.create()

we create LoL and name it as afg

JASS:
set afg.x = GetTriggerUnit()

i declare the member inside the struct .....Are all these correct?

//---------------------------------------------------------------------
Next ~
JASS:
struct ABCD
    unit u
endstruct

struct someRandomNameForAStruct
    unit u
    unit v
endstruct


unit "u" in struct ABCD and also someRandomNameForAStruct ??



How do we destroy struct to prevent leak?


Struct last along whole map or only 1 trigger or even only 1 function?
**This important...i need to know this**
 

SFilip

Gone but not forgotten
Reaction score
634
> unit "u" in struct ABCD and also someRandomNameForAStruct ??
Completely independent members.

> How do we destroy struct to prevent leak?
http://www.wc3campaigns.net/vexorian/jasshelpermanual.html#strucrest
Either call <variable name>.destroy() or call <struct name>.destroy(<variable name>).

> Struct last along whole map or only 1 trigger or even only 1 function?
From the point where you create it to the point where you destroy it.
The definition itself can be anywhere, doesn't really matter.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>Completely independent members
independent?? whats that?

>>Either call <variable name>.destroy() or call <struct name>.destroy(<variable name>).
Got that !!

>>From the point where you create it to the point where you destroy it.
The definition itself can be anywhere, doesn't really matter.

So that once i typed:
JASS:
struct ABCD
trigger u
endstruct

local ABCD AName = ABCD.create()

Then i will be able to use "AName" in other trigger after this line?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
I believe SFilip means that they are there own variables because they have different struct names, which means that when accessing them, you can use both ABCDVARNAME.u and someRandomNameForAStructVARNAME.u...

>Then i will be able to use "AName" in other trigger after this line?

Yes, I'm pretty sure.

>Are all these correct?

Yes.

:D
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
it seems that....i cant call a struct from another trigger....how do i do that?
Example:
JASS:
TRIGGER 1
struct A
string X
endstruct

function SomeFunc takes nothing returns nothing
local A AS = A.create()
set AS.X = &quot;SomeString&quot;
call EnableTrigger(TRIGGER 2)
endfunction
//--------------------------------------------------------
TRIGGER 2 (With a periodic event)

function Trig2Action takes nothing returns nothing
call BJDebugMsg(AS.X)
endfunction

How come this does syntex?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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