1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  4. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  5. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  6. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  7. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Why doesn't this function work?

Discussion in 'Triggers & Scripts' started by Bribe, Feb 11, 2010.

  1. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    This doesn't give me any syntax errors, but mind-bogglingly doesn't give me any results.

    This script is referenced...
    jass
    Code (vJASS):
    local location x = GetUnitLoc(GetTriggerUnit())
    local real c
    local real d
    call xy(c,d,x)
    call SetDoodadAnimation(c, d, 128, 'JOgr', false, "stand alternate", false)

    and it references...
    jass
    Code (vJASS):
    function xy takes real c, real d, location x returns real c, real d
    set c = GetLocationX(x)
    set d = GetLocationY(x)
    return c
    return d
    endfunction


    can anyone please tell me why nothing is happening?

    btw this was working perfectly when I was manually extracting the coordinates, so the problem is somewhere in the relationship between these two functions...
     
  2. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Code (vJASS):
    ...
            local location x = GetUnitLoc(GetTriggerUnit())
            local real c
            local real d
            call xy(c,d,x)
            call SetDoodadAnimation(c, d, 128, 'JOgr', false, "stand alternate", false)
    ...

    function xy takes real c, real d, location x returns real c, real d
            set c = GetLocationX(x)
            set d = GetLocationY(x)
            return c
            return d
    endfunction


    Functions cannot return multiple values; also you don't define the name of the variable in a return-type. What you should be doing is:

    Code (vJASS):

    local real x = GetUnitX(GetTriggerUnit())
    local real y = GetUnitY(GetTriggerUnit())

    call SetDoodadAnimation(x, y, 128, 'JOgr', false, "stand alternate", false)


    There is no need for your
    xy()
    function.
     
  3. Squiggy

    Squiggy

    Joined:
    Mar 25, 2008
    Messages:
    2,603
    Resources:
    18
    Maps:
    2
    Spells:
    15
    Tutorials:
    1
    Resources:
    18
    Why the efff.. do you want to do?
     
  4. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Code (vJASS):
    function xy takes real c, real d, location x returns real c, real d
    set c = GetLocationX(x)
    set d = GetLocationY(x)
    return c
    return d
    endfunction


    This function isn't even defined properly, it should load you with syntax errors.
     
  5. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    It's weird, game saves and loads just fine. I tried swapping the local origins into the x,y functions so that it only takes location x, and what's interesting is that even though locals c,d are not declared in the function itself it gives me no "undeclared" message even though I use c,d extensively... so weird...
     
  6. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Yea that doesn't sound right.
     
  7. Maximilianx

    Maximilianx

    Joined:
    Oct 14, 2008
    Messages:
    334
    Resources:
    0
    Resources:
    0
    Uhh, it shouldn't be
    Code (vJASS):
    function xy takes real c, real d, location x returns real c, real d

    Kind of impossible.. can only do "returns real" and the function will only return the first real you tell it to.
    Maybe something more like this:
    Code (vJASS):

    struct pair
        real x
        real y
    endstruct

    function xy takes location x returns pair
        local pair p = pair.create()
        set p.x = GetLocationX(x)
        set p.y = GetLocationY(x)
        return p
    endfunction
     


    this uses vJass though, and berbenog is completely right by the way, this xy function is useless.
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    it's not useless in that it saves having to write the same script over and over "get x of point, get y of point" where I could make a function that you just plug in one quick thing to return the desired result. I'm using NewGen to do this. I don't know the difference between Jass and VJass. In fact, I don't know 95% of what you guys know about JASS. I don't know structs and libraries and private/public. I understand globals and I understand constant functions, though.
     
  9. Maximilianx

    Maximilianx

    Joined:
    Oct 14, 2008
    Messages:
    334
    Resources:
    0
    Resources:
    0
    You should read the vJASS manual, your scripting life will be 90% easier even understanding just half of it. I'll try to give a brief explanation of a few things but I really recommend taking the time to read the manual, even if only parts of it.

    Libraries are added to the top of your maps script when jass helper compiles it, that's pretty simple, but extremely useful.

    Structs are basically a set of data stored in one easy to access object, in the example I just showed my struct is able to hold two integers, you can create a struct of that type any time you want and freely change the values, structs are accessable the same way handles are, but the syntax is different, again I suggest reading the manual.

    Now for private, if something inside of a library/scope/struct is marked private, it will be inaccessible to all code outside of that library/scope/struct.. and public is the opposite, it allows other parts of your code outside of your library/scope/struct to access the function or handle, or whatever it is you marked public/private.

    I'm not the greatest teacher ever, and the manual goes into much greater detail than I have.
     
  10. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    You obviously don't understand local variables. One function calling another can not change the value of a local variable inside either of the functions. You can only change a local variable from the scope in which it was declared (inside a function).

    If you want to change the value of a variable by calling another function, then the variable needs to be a global. You can do this:

    Code (vJASS):
    globals
        real locX
        real locY
    endglobals

    function SomeOtherFunction takes location loc returns nothing
        set locX = GetLocationX(loc)
        set locY = GetLocationY(loc)
    endfunction

    function SomeFunction takes nothing returns nothing
        local location unitLoc = GetUnitLocation( GetTriggerUnit() )
        local real x
        local real y

        call SomeOtherFunction(unitLoc)
        set x = locX
        set y = locY

        ...
    endfunction
     
  11. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    Might as well just use GetUnitX/Y...
     
  12. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    That's what she said.