Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

jass basic question 2

Discussion in 'Triggers & Scripts' started by MonkIE cReW, Oct 16, 2009.

  1. MonkIE cReW

    MonkIE cReW

    Joined:
    Oct 12, 2007
    Messages:
    148
    Resources:
    1
    Maps:
    1
    Resources:
    1
    im still reading http://www.hiveworkshop.com/forums/...als-280/beginning-jass-tutorial-series-30765/

    and i got afew more questions to ask :D (btw i dont know how 2 quote jass like with the white box so if some1 can tell me how 2 do that would be great. Rite know i'll just use normal quote)

    1)
    I asked about this in the last thread. I checked the *createunit* uhm... function (i think function is the word refering this code/command correct me if im wrong) and it says i need "takes player id, integer unitid, real x, real y, real face returns unit"
    so im guessing:
    -take player id- is player number? (like i put *1,* here and will create a unit for player one)
    -integer unitid- is the id of the unit? (like for pally is Hpal?, so in here i enter *Hpal,*? but its a integer shouldn't i enter a number instead?)
    -real x- i have no idea what this is... since its a real, i assume i enter a number here, but what does this number do?
    -real y- same with real x... no idea what this is
    -real face- lol no idea what this is either
    is this correct? lol

    2)
    i dont understand the purpose of this part ... what does the author mean by *new variable*? ...
    the way i see it it's like uhm ...
    -create a unit (…), name it *u*
    -and ... (on the line start with set u = ...) u nolonger is this unit created with function *createunit* with the identity of *…* and ... *u* turns into *other_unit* ...
    i assume this *other_unit* is like another *createunit* with a different identity like *createunit(῵ <---different number) ... rite? no? am it way off lol?

    3)
    so uhm... is *function killunit takes unit u returns nothing* part of the function of the variable?
    as in the function;
    function variable_test takes nothing returns nothing
    local unit u
    set u = CreateUnit(…..)
    endfunction
    ? or is it a different function? ... and the next example the author gives:

    doesn't have anything in the variable function ... so how does This function *use* the variable function? since i dont see any connection between the 2 ... or is the author making a completely different example?

    ty in advance :D
     
  2. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    the two functions dont relate, the only relation they have is that they both use the triggering unit as the unit being killed.

    as for the real x, real y, etc... they are the name of the parameters you are going to input in the functions, nothing more. but as you can see they also define the type of parameter you are allowed to put in, REAL x, REAL y etc, by face they mean the degrees the unit should face, aint so clear ey? Gl in learning jass bro
     
  3. dgriff

    dgriff

    Joined:
    Dec 9, 2008
    Messages:
    50
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Part 1:

    Player ID isn't a number, it's a playerid. To turn a number into a player id you use the function Player(). So putting in Player(0) or Player(1) returns player 1 and player 2 respectively (jass starts at 0, gui starts at 1 =\)

    Integer UnitID is an integer, but it's weird. It's basically a huge number that you access w/ single quotes. So 'hfoo' is the number of a footman. If you convert that number to decimal it's like 324235151523525. You were on the right track.

    Real X is the x location of the unit. The center of the map is 0, the right of the map is in the positives, the left of the map is in negatives

    Real Y is the y location of the unit. The center of the map is 0. The top is in the positives, the bottom is inthe negatives.

    Real face is the direction the unit is facing. It uses degrees so any real number between 0 and 360 will work. 0 makes it face east, 90 north etc.

    Part 2: i'll get to later...
     
  4. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    and monkie crew, if u want any help with learning JASS, il help, since most of these tutorials cause headaches and are, Crap :p
     
  5. MonkIE cReW

    MonkIE cReW

    Joined:
    Oct 12, 2007
    Messages:
    148
    Resources:
    1
    Maps:
    1
    Resources:
    1
    i dont understand what you mean by "hfoo" is a number ... its letters lol?
    and ... you said you convert it into decimal? so ... this number can't be bigger than zero? ... like 0.3834474939? and how do i turn letters into number :3

    so uhm... does this has any connection with me creating a region on the world editor? ... and how do i check where is what (x,y) value?

    <---lol
    but ty :3
     
  6. MonkIE cReW

    MonkIE cReW

    Joined:
    Oct 12, 2007
    Messages:
    148
    Resources:
    1
    Maps:
    1
    Resources:
    1
    i woulnd't call all the tutorials *craps* since they're labor of love ... or something of that nature ... but thats beside the point ...
    and yeah it is kindda confusing without some1 answering my questions ... i read the turtorial a couple times (only lesson 1-3) and my brain hurts alot :S
     
  7. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    Use [/jass] and
    Code (vJASS):
     for jass scripts (the [jass] goes first, I just reversed the order so the system doesn't parse the tags):

    [jass]
    function foo takes nothing returns nothing
    endfunction


    Use [/ljass] and
     (those r lowercase L's before jass) to do inline jass code: [ljass]function foo takes nothing returns nothing



    Number 1 seems to have already been answered, so I'll skip to number 2:

    Variables hold arbitrary data. So a unit variable named
    u
    can hold a single unit. It can be any unit, as long as that unit exists. These variables can be redefined any number of times so that they hold different data. So basically the author was saying that if you wanted to keep track of another unit you could set
    u
    equal to the second unit instead of creating a second unit variable. Of course, if you want to keep track of two units at the same time you would need 2 unit variables because one variable can only hold one piece of data at a time, so one unit variable can only hold one unit at a time.

    Number 3:

    KillUnit() is just an example function the author is using. It's a native function (one that has already been written by blizzard) that kills a unit. The author is using it to illustrate how to use local variables. You seem to have the wrong idea about variables and functions. Variables and functions are two completely different things. You don't necessarily need one to have the other. However, in most cases functions will use variables to keep track of data and sometimes you need a function to set a variable equal to something:

    Code (vJASS):

    local unit u = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
     


    The function CreateUnit() creates a unit and returns the unit that was created, which is why you can use it to set a unit variable (in this case
    u
    ) equal to something. There are other functions that return a unit, and you can use those to set variables as well (in the appropriate contexts):

    Code (vJASS):

    local unit u = GetTriggerUnit()
    local unit u2 = GetKillingUnit()
    local unit u3 = GetAttacker()
    // etc, etc
     


    But you don't need functions to set variables:

    Code (vJASS):

    local integer i = 50
     


    I just set an integer variable equal to 50 without using any kind of function.

    EDIT:

    Search: ASCII in google or wikipedia or something. Basically the short story is that in standard computer systems architecture, every english language character (including all letters, numerals, punctuation) as well as some other common characters is assigned a numeric value. In almost all programming languages, wrapping a character with ' ' (single quotes) converts the character into its assigned numeric value. Which is why 'hfoo' becomes a number.
     
  8. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    well, i do appreciate the effort into making them, but they arent good at explaining things because they get too technical, i said crap mostly because of the contempt i had for the unneeded headaches they caused me when i was learning jass xP also, in teaching it, its pretty bad >_< but it does have useful info
     
  9. MonkIE cReW

    MonkIE cReW

    Joined:
    Oct 12, 2007
    Messages:
    148
    Resources:
    1
    Maps:
    1
    Resources:
    1
    i think i understood ... 75% of this stuff XD
    and i dont know how much of this stuff i can remember D:
    cuz im not sure what i dont understand yet so ... ty *muah*
     
  10. Void

    Void

    Joined:
    Apr 16, 2009
    Messages:
    85
    Resources:
    0
    Resources:
    0
    btw hfoo is not an integer ('hfoo' is one) - thats just another representation of integers

    basically there are 3 ways to represent an integer

    1. (the normal way) (base 10)

    integer a = 16706

    2. hexadecimal (hex) (base 16)

    integer a = 0x4142
    or
    integer a = $4142
    (<=> 4*16^3+1*16^2+4*16^1+2*16^0 = 1337)

    (bold part is the prefix that indicates its a integer in hexadecimal representation)

    3. Ascii

    integer a = 'AB'
    (<=> 0x4142)
    (<=> 16706)
    (the single quotes indicate its a integer in Ascii representation)

    (just use the hexadecimal representation of each letter (http://en.wikipedia.org/wiki/ASCII))
     
  11. MonkIE cReW

    MonkIE cReW

    Joined:
    Oct 12, 2007
    Messages:
    148
    Resources:
    1
    Maps:
    1
    Resources:
    1
    uhm... so based on what you said
    so ... let see how am i gonna ask this ...
    the function:
    Code (vJASS):
    function no_name takes nothing returns nothing
     local unit u = GetTriggerUnit() <--- information set #1
     local unit u2 = GetTriggerUnit() <--- information set #2 (which is different from information #1
     local unit u3 = GetTriggerUnit() <--- information set #3 (which is different from 1 and 2)
    end function


    so basically in this whole function, 3 different unit (maybe at different location facing different places) is uhm... (what does the GetTriggerUnit do anyway? lol) ... manipulated rite? while *u* representing 3 different units

    oh and can you (or any1 else) explain:

    function no_name takes nothing <---whats this? (the "takes nothing") returns nothing <---whats this?

    thx
    sorry if im asking too many questions :3
     
  12. MonkIE cReW

    MonkIE cReW

    Joined:
    Oct 12, 2007
    Messages:
    148
    Resources:
    1
    Maps:
    1
    Resources:
    1
    i have no idea what ur talking about ... sorry lol
    im not a math genius .. im only taking calc 2 rite now :/
     
  13. Void

    Void

    Joined:
    Apr 16, 2009
    Messages:
    85
    Resources:
    0
    Resources:
    0
    thats very basic math

    and

    GetTriggerUnit()
    returns the unit that triggered the event (depends on the event - in addition it will always return the same unit in a given context so what you wrote above u, u2 and u3 would store the same unit)
     
  14. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    Well, technically, you couldn't use those three specific functions in the same function and have all three work correctly (because of how GetAttacker() and GetKillingUnit() work). But assuming that you could, u, u2, and u3 would all store units. They can be 3 different units, but this doesn't necessarily have to be the case. You can have two variables storing the same unit. You can have any number of variables storing the same unit.

    "takes nothing" just means that a function has no parameters. In other words no data needs to be passed to the function when calling it. "returns nothing" means the function has no return type; it doesn't return anything. So for example I can have a function:

    Code (vJASS):

    function Times takes real x, real y returns real
        return x * y
    endfunction
     


    This function takes in two reals (floating point numbers) x and y and returns the product of those two numbers. So every time I call the function, I need to pass it two reals and I can expect it to give me back a real:

    Code (vJASS):

    local real r1 = 5.0
    local real r2 = 10.0
    local real product = Times(r1, r2) // product will now hold the value 50.0
     


    If I have a function that takes nothing returns nothing, it needs no information and it gives me back no information:

    Code (vJASS):

    function SayHello takes nothing returns nothing
        call BJDebugMsg("Hello World!")
    endfunction
     


    When I call the function I can call it without giving it any data and I also can't retrieve any data from it. Of course you can also have functions that take in something but return nothing and functions that take in nothing but return something.