• 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] My JASS Functions

Status
Not open for further replies.

Ralle

Owner
Level 79
Joined
Oct 6, 2004
Messages
10,183
Hello guys, just wanna show off what I have spent THE LAST 3 HOURS doing:
JASS:
// mostly for debugging, outputting a string to all players by not writing much
function echo takes string text returns nothing
    call DisplayTextToForce( GetPlayersAll(), text )
endfunction
//
// input a single character and it returns if it is an integer or not
function isInt takes string input returns boolean
    local integer i=0
    local boolean r=false
    if StringLength(input) == 1 then
        loop
            exitwhen i>9
            if input == I2S(i) then
                set r=true
            endif
            set i=i+1
        endloop
    endif
    return r
endfunction
//
// returns all the numbers in a string as an integer
function phpIntval takes string input returns integer
    local integer i=0
    local string end=""
    // loop through characters
    loop
        exitwhen i > StringLength(input)
        if isInt(SubString(input,i,i+1)) then
            set end = end + SubString(input,i,i+1)
        endif
        set i = i + 1
    endloop
    return S2I(end)
endfunction

I am going to port some of the basic but powerful functions from PHP to JASS.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
BJDebugMsg() is nice for debugging, so I wouldn't use echo

phpIntval seems fine

For isInt, I would do;

JASS:
function isInt takes string input returns boolean
    local integer i=0
    if StringLength(input) == 1 then
        loop
            exitwhen i>9
            if input == I2S(i) then
                return true
            endif
            set i=i+1
        endloop
    endif
    return false
endfunction
 
Level 3
Joined
May 4, 2007
Messages
66
If I'm not mistaken, when string isn't integer function S2I() will return 0. So this function will always return true. I would do this function something like this:
JASS:
function isInt takes string input returns boolean
    if StringLength(input)==1 and ((S2I(input)>0 and S2I(input)<10) or input=="0")then
        return true
    endif
    return false
endfunction
 
Level 3
Joined
May 4, 2007
Messages
66
Yea, and i overlooked one more think. String must have 1 letter so number that is made from it can't go over 10 so i don't need S2I(input)<10, so function should look like this:

JASS:
function isInt takes string input returns boolean
    return StringLength(input)==1 and (S2I(input)>0 or input=="0") 
endfunction
 
Status
Not open for further replies.
Top