Struct/vJass Tutorials - Help wanted please

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
I've been looking at struct tutorials for a while now, both here and on wc3, and I just dont get them yet. I've read the Jasshelper manual from top to base. More than once.

The problem that I have (and maybe more people) is that most of the "tutorials" are written by programmers, and seem to be for programmers, hence it's difficult to understand it.

I don't want to clutter up their tutorial threads, with seemingly inane questions, but I (and maybe more people) really do need these most basic of questions answered. One of them was answered for me in one of the other threads (do we need the inittrig function when we make libraries. Answer was no. And yet I see Cohadar using them - and he seems to be knowledgeable about such things. ;))

Here's some examples of what I mean. The Jasshelper Manual states:
The library preprocessor allows you to keep your top functions in the top and being able to control where each one goes. It also has an smart requirement support so it will sort the function packs for you.
What does function packs mean? By using some brain power you can figure out that it means all the functions inside the library. But it isn't clear to a nonprogrammer.

Scopes can be nested, don't confuse this statement with `libraries can be nested´, in fact, you cannot even place a library inside an scope definition. You can however, have scope inside either library or scope definitions.

What is a scope? The Manual launches straight into "scoping" without giving a definition. Google define gives this: "In computer programming in general, a scope is an enclosing context. Scopes have contents which are associated with them. Various programming languages have various types of scopes. The type of scope determines what kind of entities it can contain and how it affects them. ..." Even that can be confusing. "Refers to the region within a program where a variable's value can be accessed." So does this mean things inside the scope can only be used inside the scope? Or can anything inside the library access the scope? Or is it more than that?

@Uareanoob: Structs are not globals, they are globals + methods + create + onDestroy + ...
@chovynz: There are a lot of tutorials on the subject of structs no need to explain that in here.

...

Structs are NOT globals, they are parallel global arrays (synchronized with .this) + an internal array indexing capability.

STRUCTS ARE INTEGERS.

There are about 29 Struct/vJass threads on this forum. The others are just specific questions about specific maps/problems. There are 3 tutorials specifically on TheHelper. There are a few more on Wc3C but not many more and are mostly repeats.

The threads that do ask about structs/vJass problems (mostly at Gals starting point) very quickly disintegrate into an "elite" duel about this or that is better and why isn't he using this system or that inside the scopes/libraries.

Please. Can someone write a vJass tutorial that explains it from the ground up. If you want GUIers to start switching to Jass or vJass you need to give us some more help than talking in programming language. I know this is a programming language here, but surely you can talk about it in a simple way so that someone who knows nothing about it can start using it? Although Doomhammer does a little programming language, his post is like gold. Clearly explained and in depth.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Question 1: Do you know what the map header is? The thing, in the trigger editor, above all files named *.w3x? By creating library, the code inside it is simply trasfered there! Code in the header is simply read before all other code, thus functions there can be used from everywhere.

Question 2: There is a very detailed explanation about scopes in the NewGen's manual. Look at the table of content for scopes. You'll find it, I'm sure.

Question 3: Actually, there are a lot of vJass tutorials, and the best one is the NewGen manual. Creating a new one will be a total waste. Why don't you approach your problem by asking more direct questions.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Question 1: Do you know what the map header is? The thing, in the trigger editor, above all files named *.w3x? By creating library, the code is them is simply trasfered there! Code in the header is simply read before all other code, thus functions there can be used from everywhere.

Question 2: There is a very detailed explanation about scopes in the NewGen's manual. Look at the table of content for scopes. You'll find it, I'm sure.

Question 3: Actually, there are a lot of vJass tutorials, and the best one is the NewGen manual. Creating a new one will be a total waste. Why don't you approach your problem by asking more direct questions.

Q1. Thanks. Thats the first time I've heard that. And it makes a whole lot more sense put that way.

Q2. I've read it. That part I quoted was taken directly from the scopes bit. It isn't as clear as you think. But -.- I will read it again. Probably another 100 times.

Q3. This is true. I will do so. Thanks for the reminder of why TH is here. I get caught up in trying to help others lots I forget to ask about my own things.

However, I will say this. Vexorian, although he is VERY smart, or at the very least one of the ones that starts us on this road of self-enlightenment (of finding out that I am NOT in fact any kind of programmer ;)) sometimes finds it difficult to explain to us nonprogrammers what he is trying to say. That goes for Cohadar and some of the others too. This is not for lack of trying. The blockage is more from the people whom they are trying to teach. But it doesn't change anything to say "Go read the manual." That is one of the reasons I have posted this thread - the difficulty I have had in reading and understanding the NewGen Manual.

Thanks for your encouragement Rheias.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Q2: Basically, scopes are blocks of code. For example

JASS:

scope s
    function f1 takes nothing returns nothing
    endfunction

    function f2 takes nothing returns nothing
    endfunction

    function f3 takes nothing returns nothing
    endfunction
endscope


Those 3 function are placed inside the scope. Scopes are basically, helping us to orginize our code. Further more, they make it easier for people to read the code, so when taking our code public, more people could read it. That is, as far as I understand at least, the goal of scopes.

How can this be done? First of all, we can nest scopes.

JASS:

scope s
    function f1 takes nothing returns nothing
    endfunction

    function f2 takes nothing returns nothing
    endfunction

    function f3 takes nothing returns nothing
    endfunction

    scope ss
        function f4 takes nothing returns nothing
        endfunction
    endscope
endscope


We can also take function public or private. Public means a prefix will be added to them, for example s_f1 and private means outside the scope, those function will not be accessible.

There are probably a few more things I forgot to mention regarding scopes, however, I'm sure you'll be able to understand them when re-reading the scopes chapter (I read it about 3 times ;)), and if you are having trouble, all you need to do is ask here.

Q3: To put it in a simple way, structs can hold pointers to data, and when accessing the struct we can get the pointers and manipulate the data they are pointing to. When using structs correctly, it is like using Kattan's handle system, or CS_Cache.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
<<< Ignore that. It appeared out of nowhere.

Public means a prefix will be added to them, for example s_f1 and private means outside the scope, those function will not be accessible.

So I can access things from outside a scope? i.e.

JASS:
scope food
    function icecream takes nothing returns nothing
    endfunction
endscope

    function eat takes nothing returns nothing
    call ExecuteFunc (icecream)
    endfunction


JASS:
scope food
    private function icecream takes nothing returns nothing
    endfunction
endscope

    function sad takes nothing returns nothing
    call ExecuteFunc (cannot eat icecream)
    endfunction


Edit: I don't know why that thumbs down appeared there. It wasn't my intention to put it there (or anywhere) , just ignore it.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
As far as I understand, yes, this is the case. Note that if you would have put public then the prefix was scopeName_functionName.
 

Cohadar

master of fugue
Reaction score
209
Question 1: Do you know what the map header is? The thing, in the trigger editor, above all files named *.w3x? By creating library, the code inside it is simply trasfered there! Code in the header is simply read before all other code, thus functions there can be used from everywhere.

This is ABSOLUTELY NOT TRUE, and is a common misconception among novice mappers.

Libraries are NOT SIMPLY transfered to map header.
Libraries were invented just for the purpose of NOT USING map header.

I have seen people putting libraries directly into map header because of this misconception.

USING MAP HEADER IS THE WAY OF NOOBS.

I will give an example here:
Lets suppose you are making a system for dummy casters:
JASS:

library Dummy

function createDummy takes player p returns unit
    // In this function you create dummy unit and among other stuff
    // use ABC to attach dummy to a timer for some reason
endfunction

//----
endlibrary


and lets suppose you have this triggers in your map:
Code:
Spell1  (uses ABC)
Spell2  (uses global arrays)
Spell3  (uses dummy caster sys)
Dummy (library)
ABC     (library)
Ok so you know Dummy is a library so all functions inside Dummy library will be available to all of your triggers because libraries are processed before triggers.

This is how compiled map looks like:
Code:
Dummy (library)
ABC     (library)
Spell1  (uses ABC)
Spell2  (uses global arrays)
Spell3  (uses dummy caster sys)

Thats' it, all libraries are put before triggers.

So in your Spell3 trigger you can use createDummy function without a hussle.
(before libraries you had to put that function in map header)

But ABC is also a library, if Dummy library uses SetTimerStructA it means that ABC must be put before Dummy.
If Dummy is before ABC jasshelper will give you error saying he cannot find SetTimerStructA function. (because that function is declared after Dummy is processed)

Ordering the triggers inside WE will not help you,
WE does not care if some triggers are put before others in the list.

So the only way to put ABC in front of Dummy is to use uses keyword

JASS:

library Dummy uses ABC

function createDummy takes player p returns unit
    // In this function you create dummy unit and among other stuff
    // use ABC to attach dummy to a timer for some reason
endfunction

//----
endlibrary


Jasshelper will now properly order stuff and it will compile ok.
Code:
ABC     (library)
Dummy (library)  {Dummy uses ABC so it is put after ABC}
Spell1  (uses ABC)
Spell2  (uses global arrays)
Spell3  (uses dummy caster sys)

Before libraries you had to order your systems manually,
and you had to put them all in map header.
This resulted in map headers with more than 10000 lines and if some error happened there you were screwed.
Searching an error in 10000 lines of code is .... you know.

So let me just say this one more time:
USING MAP HEADER IS THE WAY OF NOOBS.

Use libraries.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Cohadar, I was explaining what the effect is.
Libraries > Map header, yes, but using libraries, is basically using the header, just in a cleaner fashion.
 

Cohadar

master of fugue
Reaction score
209
Yes but making parallels between stuff without explaining the differences misguides people.

Half-truth is more dangerous than a lie.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Thank you both of you. That was helpful.

So talking about libraries...
We don't/shouldn't need to make a spell INSIDE the library correct? But we can do something, maybe a slide function or a turn unit invisible function, inside the library so that any spell (that uses a slide or invisible) can access that slide.

Then we can call that slide function from outside the library? Do I understand it correctly?

Cohadar:
USING MAP HEADER IS THE WAY OF NOOBS.
You say this a few times. I got the message. But I have a question. Would it be better to skip making any triggers in gui at all and use ONLY the map header for all of your entire functions, including all libraries and structs and such? If you know what your doing you can make InitTrig functions yourself. Thoughts on that?
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Would it be better to skip making any triggers in gui at all and use ONLY the map header for all of your entire functions, including all libraries and structs and such? If you know what your doing you can make InitTrig functions yourself. Thoughts on that?
Have fun looking for that 3 line function somewhere in the middle of 10000 lines :). What I'm trying to say is that it will be a true maintenance nightmare and it's exactly that the library ordering tries to avoid.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Ok phyrex1an. Understood. Thanks. So good practice is to make a GUI trigger with the name of the spell there, and put all relevant functions in there. And maybe have a GUI trigger called Libraries? Or should those also go in the spell trigger (i.e. for good implementation into other peoples maps.)

Next question. If libraries are put in front of everything, why do we use scopes and methods inside libraries?

As in...I'm trying to understand why we have so many different things inside other things. There is no inheritance so why is it structured like there is inheritance?

Why not just write and call certain functions when we need them?
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
Probably for organization. I myself have never actually put a scope inside a library. And the point of having functions in libraries is like the same point as putting stuff in your map header. Some things need to be loaded before others. Also, functions inside libraries can be private, so you can stick with simple names, because private members inside a library can have the same name as something outside of a library.
 

SFilip

Gone but not forgotten
Reaction score
634
> And maybe have a GUI trigger called Libraries
Dump them all in one trigger? What exactly is the advantage of doing that over using the map header :rolleyes:
One GUI trigger per library is probably the best thing to do. Use scopes for spells, and if you have some functions more than one spell uses then put them in a library.

> why do we use scopes
Further organization, private functions etc.

> and methods
Well...these aren't really related to libraries, but structs instead.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
I think he meant "members".

I have no idea what you are refering to. *edited*

SFilip said:
> why do we use scopes
Further organization, private functions etc.

> and methods
Well...these aren't really related to libraries, but structs instead.

Ok. Scopes kind of make sense now. Not sure yet how I would use them but I'll keep them in mind.

Q2. Libraries, structs and globals all have the same level in the function heirarchy correct? Scratch that.
Q3. What are the global blocks I keep hearing about?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
I have no idea what you are refering to or who you are talking to. I also don't know you. I know Cohadar, Vex, Sfilip, some others, and trust what they say more than what you say. Sorry. Just the way it goes. Feel free to keep posting though, because I'm learning things.

Don't worry, TheKingPin is someone you can definitely trust. ;) He may be new to this site, but he isn't new to JASS.

Also, for Q2, do you mean that all of them execute/are read at the same time?
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Don't worry, TheKingPin is someone you can definitely trust. ;) He may be new to this site, but he isn't new to JASS.

Also, for Q2, do you mean that all of them execute/are read at the same time?

And you think I can take your word? ;) j/k

Q2. Noes. I'm not talking about execution at the moment. I'm talking about what we see them as and were they can go. Like this:

JASS:
library Dummy
   set blah=blah
endlibrary

struct
   whatever goes in here
endstruct

globals
   somevariable variablename 
endglobals


//------Also

library Dummy
   globals
      somevariable variablename 
   endglobals
endlibrary


Q3. Just to clarify, are global blocks where you create global variables?
 
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