• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Simple Return Question

Status
Not open for further replies.
Level 6
Joined
Jun 30, 2006
Messages
230
JASS:
globals
    force udg_Alliance
    force udg_Horde
endglobals
function WhichForce takes integer i returns force
    local force f
    if i<10 then
        if i<5 then
            set f = udg_Alliance
        else
            set f = udg_Horde
        endif
    endif
    return f
endfunction
function Blah takes nothing returns nothing
    local integer i = 0
    local force g
    set g = WhichForce(i)
endfunction
That works, but if you add 'set f = null' after returning f, it doesn't work. "Return types not correct or nonexistant returns" If you've returned f, can't you null it? Or does JASS not work like that? Other programming languages I know can do this. It looks like to me that I have to have a leak :/ I'm just checking to make sure this is the case.
 
No, because f is declared as a local in that function, not the other.

When nulling f, it clears the variable so f = . " " is nothing without the qoutes so it syntaxes.

What you could do instead, (I think) is do this:
JASS:
function WhichForce takes integer i returns force
    if i<10 then
        if i<5 then 
            return udg_Alliance
        else
            return udg_Horde
        endif
    endif
endfunction

That should work without leaking. (I forgot if forces leak, if so, just Destroy the force). :thumbs_up:
 
Level 6
Joined
Jun 30, 2006
Messages
230
Purp, do you not know PHP? It can do anything! Not really, but it's a lazy programming language. It lets you do a lot of things.

I tried the same thing (I had thought) earlier and it kept giving me errors. Must have had a typo that I couldn't see because it parses now. Edit: It doesn't parse
JASS:
function WhichForce takes integer i returns force
    local force f
    if i<10 then
        if i<5 then
            return udg_Alliance
        else
            return udg_Horde
        endif
    endif
endfunction
If I add null, like this:
JASS:
function WhichForce takes integer i returns force
    local force f
    if i<10 then
        if i<5 then
            return udg_Alliance
        else
            return udg_Horde
        endif
    endif
    return null
endfunction
Then it will always return null, regardless of the previous returns, unless it quits after the first return? Can't test to see if it works, my other three comps crashed. Help me out?
 
Last edited:
1. Don't have the "local force f", it needs to be nulled and it is a waste of a line because it isn't used.

2. It exits after the first return.

Since "Skip Remaining Actions" is "return" in JASS, return would exit the function immediately and skip the remaining actions; that's what I'm assuming. I'm pretty sure of this, otherwise just add "return" after the returns or something such as that. :thumbs_up:
 
Level 6
Joined
Jun 30, 2006
Messages
230
Forgot to take out that line when I stopped using a variable. Off-line I had it right though. My question is, if an integer equal to 10 or higher is passed, it returns null. Then, I use ForForce(f(the force returned which equals null),Blah()) What happens?
 
Status
Not open for further replies.
Top