• 🏆 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!

[JASS] My JASS Functions

Status
Not open for further replies.

Ralle

Owner
Level 77
Joined
Oct 6, 2004
Messages
10,101
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