• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[vJASS] About a return bug.

Status
Not open for further replies.
Does anyone know the fix for this?

function StrID takes string s returns integer
return GetLocalizedString(s)
return 0
endfunction

Use the native, StringHash:

JASS:
function StrId takes string s returns integer
    return StringHash(s)
endfunction

This should work unless the maker of the map compares ID's explicitly, such as StrId(s) == 5124. However, that is unlikely because most people just use it to hash strings into an integer for saving in gamecache.
 
I'll try to look at it when I have time. It is a bit late right now, so I'll probably look at it tomorrow. Here is one problem:
JASS:
function CollDataContainsId takes integer data,integer id returns boolean
        if data == Power2[id] then
            return true
        endif
        
        if data > Power2[id] then
            set id=11
            loop
                exitwhen id < 0
                if data >= Power2[id] then
                    //in this case the player has already been hit by coll func, so no more dmg is done
                    set data=data - Power2[id]
                    if id == Obj_OwnerId[TCollObj] then
                        return true
                    endif
                endif
                    
                set id=id - 1
            endloop
            return false
        else
            return false
        endif
    endfunction

There is no default return. I am pretty sure Wc3 doesn't accept this anymore. Even though technically, it will return false, Wc3 doesn't recognize that. Change it to this:
JASS:
function CollDataContainsId takes integer data,integer id returns boolean
        if data == Power2[id] then
            return true
        endif
        
        if data > Power2[id] then
            set id=11
            loop
                exitwhen id < 0
                if data >= Power2[id] then
                    //in this case the player has already been hit by coll func, so no more dmg is done
                    set data=data - Power2[id]
                    if id == Obj_OwnerId[TCollObj] then
                        return true
                    endif
                endif
                    
                set id=id - 1
            endloop
            return false
        endif
        return false
    endfunction

Here is another:
JASS:
function GetHeight takes real x,real y returns real
    local real real_h
    local real cliff_h
        
    call MoveLocation(TLoc, x, y)
    if CliffSimulation then
        set real_h=GetLocationZ(TLoc)
        set cliff_h=( GetTerrainCliffLevel(x, y) - BaseCliffLvl ) * 128
        if cliff_h > real_h then
            return cliff_h
        else
            return real_h
        endif
    else
        // return GetLocationZ(TLoc)
    endif
    return GetLocationZ(TLoc) // I moved it here 
endfunction

There are actually quite a few functions like that. Usually, it is just moving the "else" return below the "endif". You can try it yourself, but if you are willing to wait I'll try to get a modified war3map.j with the appropriate fixes by tomorrow, since there are 191 "returns" to look through.

If you can, post a message on my profile or send me a PM so that I will remember. I tend to forget.
 
Yes, return skips remaining actions.

However, the issue comes from the patch to fix the return bug. They made it so that you can't return: (a) mismatched type (b) if the function says it returns something, then the function must return something at some point in the code. (meaning, you can't say you are going to return something, and have no returns) Ex:
JASS:
function Example takes real a returns real 
    if a == 5 then
        return 6.
    else
        return 7.
    endif
endfunction

Even though this will logically return 6 or 7 in all cases, iirc Wc3 won't realize this and the map won't start. The final return has to be moved below the endif in this case.
 
Status
Not open for further replies.
Top