Struct/vJass Tutorials - Help wanted please

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> Q2. Libraries, structs and globals all have the same level in the function heirarchy correct? Scratch that.

As far as I know:

globals
libraries
structs

Although I'm sure Cohadar will jump from somewhere is a hammer to fix some mistake.

> Q3. What are the global blocks I keep hearing about?

Where you create global variables, like the variable editor, however they are used just like libraries:

JASS:
globals
    variabletpye array? variablename
    ...
endglobals
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Ok. So I think I understand globals (you would ONLY create (=declare?) global variables in those global blocks correct? You would not also put other functions in the globals?

I am on the way to understanding libraries (i.e. make all functions inside the library be read first and able to be called from anywhere.)

Structs: Are a way of putting multiple variables into one? I.e. ... something.
What is the ".create" and ".destroy". It's obvious by their name that they create and destroy something...but what is that something?
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Kingpin

I think he meant "members".

I apologize for my stupid comment before. That was arrogant of me. I understand what you mean now.
Since I made it so public before, I thought I'd better do the same in putting it right. No hard feelings?

I'd like to hear more from you in this thread if you are willing. :)
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
Structs are sorta hard to explain/understand... but...

Struct is short for Data Structure. Think of it sort of like a package. It has things inside of it. Variables and functions. In a function, you can create a new "package" with the .create method (functions inside structs are called methods.). Here's an example.

JASS:
struct MyStruct // Treat this like a template.
	integer a = 5
	integer b = 5
endstruct

function DoSomething takes nothing returns nothing
	local MyStruct var = MyStruct.create() // Treat a struct name like a type of variable. .create() makes a new instance of a struct based on MyStruct.
	call BJDebugMsg(I2S(var.a)) // Displays "5".
endfunction


You access things inside a struct with <structvar>.<variablename> . Sort of like how you find files in your computer: My Computer/My Documents/Pictures/photo.jpg Sort of like that, but with dots instead of /es.

the .destroy() method destroys an instance of a struct (Important! you can only have 8190 instances of a single struct out at one time!)

Structs aren't just for holding variables, they can have functions inside of them too. They're called methods.

JASS:
struct MyStruct
	integer a = 5
	integer b = 5

	method Add takes nothing returns integer
		return this.a + this.b //use &quot;this&quot; to get variables inside a struct.
	endmethod
endstruct

function DoSomething takes nothing returns nothing
	local MyStruct var = MyStruct.create()
	call BJDebugMsg(I2S(var.Add())) // Displays &quot;10&quot;.
endfunction


Plus one of the great things about structs is that you can use them instead of handle variables. You can store a struct (as integer) holding all the values onto a unit instead of attaching multiple variables to a unit.

There's a lot lot more to structs, I won't get into them just yet.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Q7. Structs don't actually do anything by themselves? Q7b.They are a holding pen for your sheep (variable values?)

Q8. You use "this.something" to get variables from inside structs when you are inside? Q8b.You cannot do the same thing from outside a struct? (You would use the struct name instead to get the variables i.e. from your example.) (I think you said exactly that.)

You access things inside a struct with <structvar>.<variablename> . Sort of like how you find files in your computer: My Computer/My Documents/Pictures/photo.jpg Sort of like that, but with dots instead of /es.

Q9.Is "this." a universal thing or is it only for inside structs?

I can sorta see why you would not separate your libraries and structs from the spell trigger. Some spells would not make sense if you did that, even if they do work. You would be scratching your head wondering where some variables and calls came from.

Q10. So, what does before and after preprocessing look like? Taking your example again...
Before
JASS:
struct MyStruct // Treat this like a template.
	integer a = 5
	integer b = 5
endstruct

function DoSomething takes nothing returns nothing
	local MyStruct var = MyStruct.create() // Treat a struct name like a type of variable. .create() makes a new instance of a struct based on MyStruct.
	call BJDebugMsg(I2S(var.a)) // Displays &quot;5&quot;.
endfunction


The preprocessor does something like this?

JASS:
//struct MyStruct // Treat this like a template.
//	integer a = 5
//	integer b = 5
//endstruct
// My guess is this actually gets deleted.

function DoSomething takes nothing returns nothing
	local integer var = 5
	call BJDebugMsg(I2S(var)) // Displays &quot;5&quot;.
endfunction
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
I got it! (i think - sorry for double post - just so excited that i might have got it.)

Structs are arrays! Kinda - They are the vJass equivalent of []?
Please tell me I'm correct...
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Q7. I'm not sure I understand you... Mind rephrasing that?
Q8. Precisely.
Q9. this. works only in structs, where else would it be useful? Note that this. can be replaced with one simply . .
Q10. Nope, by all means it doesn't work like that, although I'm not entierly sure how it DOES work. This is the time for Vexorian to come in and clarify this.

As for saying structs are arrays, basically yes. I mean, no, however you may think of them as array, when instead of [#] you put .string.
 

Cohadar

master of fugue
Reaction score
209
Apprentice:
Master I do not understand this kung-fu technique,
it is complicated, it is hard and it makes no sense to me,
I think it is of no use.

Master Fu:
Do not think but do,
you need not understand to use,
when you use, understanding comes to you.
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
Apprentice:
Master I do not understand this kung-fu technique,
it is complicated, it is hard and it makes no sense to me,
I think it is of no use.

Master Fu:
Do not think but do,
you need not understand to use,
when you use, understanding comes to you.
lol i was thinking the same thing all this questions make it more confusing than the actual use of it....
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
Apprentice:
Master I do not understand this kung-fu technique,
it is complicated, it is hard and it makes no sense to me,
I think it is of no use.

Master Fu:
Do not think but do,
you need not understand to use,
when you use, understanding comes to you.

Q F T

Like me, I learn by doing.

Here' I'll post another example of it's usage.

JASS:
struct MyStructA
	string s = &quot;ham&quot;
endstruct

struct MyStructB
	string s = &quot;cheese&quot;
endstruct

function DoSomething takes nothing returns nothing
	local MyStructA a = MyStructA.create() // New instance of MyStructA
	local MyStructA aa = MyStructA.create() // Another instance of MyStructA
	local MyStructB b = MyStructB.create() // New instance of MyStructB
	call BJDebugMsg(a.s+&quot; and &quot;+b.s) // Displays &quot;ham and cheese&quot;
	set a.s = &quot;foo&quot;
	set b.s = &quot;bar&quot;
	call BJDebugMsg(a.s+&quot; &quot;+b.s) // Displays  &quot;foo bar&quot;
	call BJDebugMsg(a.s+&quot; &quot;+b.s+&quot; &quot;+aa.s) // Displays &quot;foo bar ham&quot;
	call a.destroy()
	call b.destroy()
        call aa.destroy()
endfunction


Here's another example using methods.

JASS:
struct Blah
	real a = 61
	real b = 9
	unit f = CreateUnit(&#039;hpea&#039;,Player(0),0,0,0)

	method Add takes nothing returns real
		return this.a + this.b //this = the struct instance containing the method.
	endmethod

	method Kill takes nothing returns nothing
		call KillUnit(this.f)
	endmethod
endstruct

function DoSomething takes nothing returns nothing
	local Blah s = Blah.create()
	call BJDebugMsg(R2S(s.Add())) // Displays 70.
	call s.Kill()
endfunction
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
JASS:
return this.a + this.b

from where execly did you call for this.a?
i didn't see you declare any "this"
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
so it doesn't matter whatever the struct name is as long as the method is inside it i could refer it as this.<variable>?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Yes, this. is just like using the struct's name. Note that you could do .member instead of this.member.
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
so it doesn't matter whatever the struct name is as long as the method is inside it i could refer it as this.<variable>?

this.<variable> or just .<variable>. However, it cannot be used in static methods or on static members.
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
it cannot be used in static methods or on static members.
assuming i didn't hear this one i think i understood.... (i don't wanna hijack the thread..)
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
assuming i didn't hear this one i think i understood.... (i don't wanna hijack the thread..)

Go for it. The more understanding we get the better.

Q13442. Statics are private globals inside a struct?

Cohadar said:
Apprentice:
Master I do not understand this kung-fu technique,
it is complicated, it is hard and it makes no sense to me,
I think it is of no use.

Master Fu:
Do not think but do,
you need not understand to use,
when you use, understanding comes to you.

This.29 = brilliant lol. Although it might be a little ahead of my predicament. I .... yes master. I go to do.
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
Almost, they're just not private.
Statics are members of a struct that are not instanced, hence the name "static".

Here's an example:
JASS:
struct MyStruct
	integer a = 4
	static integer b = 5
endstruct

function Do takes nothing returns nothing
	local MyStruct m = MyStruct.create()
	call BJDebugMsg(I2S(m.a)) // Displays &quot;4&quot;.
	call BJDebugMsg(I2S(m.b)) // Error
	call BJDebugMsg(I2s(MyStruct.b)) // Displays &quot;5&quot;.
	call m.destroy()
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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