• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] [Wurst] Function returns multiple values possible?

Status
Not open for further replies.
Level 2
Joined
Feb 27, 2019
Messages
14
Is it possible in Wurst for a function to return multiple values? It seems it is with JASS. E.g. I would like to find the closest camp and if none are found as ready return a false. Alternatively I could wrap it into another function that returns nothing and simply doesn't do the deed if the returned integer is -1.

General code comments are also very welcome.

Thanks

Wurst:
function findClosestReadyCamp (vec2 target) returns int
    real closestDistance = REAL_MAX
    bool isAccepted = false
    int closest = 0 // location of the camp as index in an array (called wilds), this can be initialized instead to -1
    for i = 0 to wildsLastIndex // pesky non sized arrays making me do this, array should prolly be refactored as a separated class to get sized arrays, as I've read something like
    // for WildLoc w in wilds would "leak"
        if not isAccepted
            if wilds[i].isReady // array of classes
                let dist = target.distanceToSq(wilds[i].loc) // squared distances are much cheaper, loc (location as vec2) is pre-saved on map initialization
                if dist < closestDistance
                    closestDistance = dist
                    closest = i
                if dist < 9000000 // if a camp is this close (3000 sq) no need to check the rest of the camps
                    isAccepted = true // break out of loop
    return closest
 
Last edited:
Level 11
Joined
Dec 16, 2018
Messages
365
I have no idea how to use JASS, but as a desperate GUI user, I think it's a way.
First detect if there is a nearby unit, which specifically should be a camp. If found, a real would be increased to 2, and the desired actions would be carried out. Once these actions are finished, the same real one would pass to 0, its null state.
To close the Else of if / then / else, if the nearness conditions are not met, the value of the Real goes to 1, and a personalized message could come out, or whatever. After a few seconds, the Real would also pass to 0. Thus, it would be as simple as detecting the value of that real in every skill or detonator in which this is required.
I'm not sure this is what you are requesting, but if not, just take it as a message
 
Status
Not open for further replies.
Top