brand new jass beginner +rep for help

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
thanks everyone for helpin out, if i have not +repped you yet, it is coming, i just maxxed out rep given out in 24 hrs

so here is what i got:
when the code is compiled it essentially adds all the functions to the maps code, essentially 1 long list of code, but it adds them in a random order, using libraries puts functions at the top of the code and in order for a function to be called by another it needs the other to be above it in the code, thats why libraries are used, scopes are used to make functions private so they cant be called by other functions and to organize it all together better (ie the scope is multiple functions that are added to the code in a grouping rather than in random places)
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
ok i was very confused for a while as to why to use scopes over functions and libraries over scopes but now i understand, what about making functions private and public? is that only in scopes/libraries?

EDT:

here is a list of what i would use libraries/scopes/functions for (just examples):

Libraries: a damage system or castbar system

Scopes: a multiple function spell that requires 1 or more libraries

Functions: a simple trigger that does what isnt required to be called again for any reason

are all of those correct?
 

Dirac

22710180
Reaction score
147
scopes cant require anything, so if you create a scope you asume that it automatically requires anything, however if you want a library to require another specific library you go
JASS:
library MyLib uses LibA, LibB, LibC

Scopes / Libraries can't be compared to functions since they are what encapsulate them
Example
JASS:
library A
    function Hello takes nothing returns nothing
        call BJDebugMsg("hello!")
    endfunction
endlibrary

library B initializer onInit uses A
    private function onInit takes nothing returns nothing
        call Hello()
    endfunction
endlibrary
JASS:
library A
    function Hello takes nothing returns nothing
        call BJDebugMsg("hello!")
    endfunction
endlibrary


//Scopes use all libraries
scope B
    private function onInit takes nothing returns nothing
        call Hello()
    endfunction
endscope

But this would cause syntax error
JASS:
library A
    //notice that the hello function is now private, can only be
    //called inside library A
    private function Hello takes nothing returns nothing
        call BJDebugMsg("hello!")
    endfunction
endlibrary

library B initializer onInit uses A
    private function onInit takes nothing returns nothing
        call Hello()
    endfunction
endlibrary
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i understand you cant have requirements for scopes, but they require the libraries because they call them, and the libraries are above them, i assume if you call a function thats supposed to be in a non-existant library the scope doesnt work, correct?
 

Dirac

22710180
Reaction score
147
You don't have to specify from which scope the function is in order to call it
Most likely it would cause syntax error if the function is BELOW the function calling it or the function name isn't correct or doesn't exist
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
think you misred that last post, but i get the main point, thanks a bunch dirac
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
at work and that site is blocked, will check it out when i get off
 

Ayanami

칼리
Reaction score
288
Functions: a simple trigger that does what isnt required to be called again for any reason

Functions aren't triggers. A function is basically your "paper" to write your codes in. If you attempt to write any code outside of a function, you'll get an error.

Then you might ask why can't we code everything in 1 function? Well, you could, but it would be hell if you're trying to debug. Also, your code will be in a mess. Plus, you'll have limitations as well. Thus, you need multiple functions.

Just want to ask, do you know what Functions do? Like about parameters, return type, etc.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i have a basic idea but im still a beginner as far as jass goes, ill follow a few tutorials on it
 

Ayanami

칼리
Reaction score
288
i have a basic idea but im still a beginner as far as jass goes, ill follow a few tutorials on it

Yeah, I suggest grasping concepts of Functions, Variables, etc before moving on to grasping ideas of Libraries, Scopes, Structs, etc.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i understand variables and functions, just dont know returns yet
 

Ayanami

칼리
Reaction score
288
i understand variables and functions, just dont know returns yet

Return is a part of Function. Basically, it returns a value. Some Functions don't need to return at all.

JASS:
// function does not need to return anything as this function this simply performing a task: displaying a unit's name and then kill it
function DisplayAndKill takes unit u returns nothing
    call BJDebugMsg(GetUnitName(u))
    call KillUnit(u)
endfunction


JASS:
// this function basically adds 2 integers together and returns the sum
function GetSum takes integer a, integer b returns integer
    return a + b
endfunction

// a test function for GetSum
function Test takes nothing returns nothing
    // let's say you want to get the sum of 5 and 10 using GetSum function
    int sum = GetSum(5, 10) // this calls the function. GetSum returns an integer. Thus values 5 and 10 are passed to the GetSum function. GetSum then returns 15 and the value is stored in the variable sum.
endfunction


This is what you would use returns for. You need it if you wish to pass a value to the function you previously called. Things like [ljass]CreateUnit[/ljass], [ljass]CreateGroup[/ljass], [ljass]IsUnitType[/ljass] have returns. Things like [ljass]KillUnit[/ljass], [ljass]RemoveUnit[/ljass], [ljass]DestroyGroup[/ljass] don't have a return.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i understand, boolean would return true/false or 1/0 correct
return unit would get the unit that it returns based on what is inputted
return integer would return (a, b, c, d...) correct?

would i do this to get a unit from a triggering unit? this is gonna be freehand so bare with me:

JASS:
function GetUnit takes unit a returns unit
  return udg_Unit_Target[GetUnitHandle(a)]
endfunction

function Test takes nothing returns nothing
  unit u = GetUnit(whatever unit you want)
endfunction


this should get the units target if saved in the variable Unit_Target correct?

what are all of the possible returns?
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
thanks, would the trigger above, the one that i posted free hand, work out right?
 

Ayanami

칼리
Reaction score
288
i understand, boolean would return true/false or 1/0 correct
return unit would get the unit that it returns based on what is inputted
return integer would return (a, b, c, d...) correct?

It's not really necessary that return value is dependent on input values. For example, you can have a function that returns the integer value 5 without any input. The return value really depends on what you want to return. Boolean is only true/false, 1/0 are not accepted as boolean. Return integer basically returns an integer value. Return real basically returns a real. You get the idea.

would i do this to get a unit from a triggering unit? this is gonna be freehand so bare with me:

JASS:
function GetUnit takes unit a returns unit
  return udg_Unit_Target[GetUnitHandle(a)]
endfunction

function Test takes nothing returns nothing
  unit u = GetUnit(whatever unit you want)
endfunction


this should get the units target if saved in the variable Unit_Target correct?

Yes, you're right. However, you could just do:

JASS:
function Test takes nothing returns nothing
  unit u = udg_Unit_Target[GetUnitHandle(Some Unit)]
endfunction


But yeah, the way you wrote works as well.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
just using that as an example for how to use the return part of the function, i understand now
so what it takes, is that a variable that has to be declared in globals or is that just a value that is used? like a local
 

Ayanami

칼리
Reaction score
288
just using that as an example for how to use the return part of the function, i understand now
so what it takes, is that a variable that has to be declared in globals or is that just a value that is used? like a local

For the parameters (what it takes), the variables are declared there. So they're basically locals, but you don't need to null parameters, unlike local 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