• 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.

[vJASS] What is wrong with this code

Status
Not open for further replies.
I want to understand JASS, and as I move on reading some tutorials, I was able to grasp simple knowledge of it, but, this little problem is bothering me. What is wrong with this code?
Please, could someone be kind to explain. The JASS checker in JNGP says this has no errors but, this won't run the game. The game seems loading but it just like pause and doesn't open the game.
JASS:
function Action_Create_Unit takes nothing returns nothing
    local integer u_int = 'hpea'
    local real x = 1
    local integer u_Num = 1
    local real y = 1
    local player p = Player(0)
    local integer time = 5
    local unit u
    local string t_string = "This is my first Jass"
call BJDebugMsg(t_string)
        if time > 0 then
            set time = time - 1
            loop
                exitwhen time == 0
                call CreateUnit(p, u_int, x, y, 0)
            endloop
        endif
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    set gg_trg_Melee_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Melee_Initialization, function Action_Create_Unit )
    call TriggerRegisterTimerEventPeriodic(gg_trg_Melee_Initialization, 1)
endfunction
 
Level 11
Joined
Mar 31, 2009
Messages
732
infinite loop

JASS:
if time > 0 then
        set time = time - 1
        loop
            exitwhen time == 0
            call CreateUnit(p, u_int, x, y, 0)
        endloop
    endif

JASS:
if time > 0 then
        loop
            set time = time - 1
            exitwhen time == 0
            call CreateUnit(p, u_int, x, y, 0)
        endloop
    endif
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
@ eubz:
Glad that you are learning JASS cause GUI sucks, now into the matter at hand it is as Teelo said this will cause the loop not to exit and since you are creating a unit inside the loop and the loop is almost instant its like creating infinity unit in zero time which will crash the game.
 
Level 11
Joined
Mar 31, 2009
Messages
732
I didn't understand what he meant by
The JASS checker in JNGP says this has no errors but, this won't run the game. The game seems loading but it just like pause and doesn't open the game.
so the first thing I did was run the code myself to see what happens.

I would like my 30 trillion or so CPU cycles back, please.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
He means there is no syntax error in the structure of the script but the game don't run because this function run at map initialization; meaning after the loading is done. The function create infinite units which will eventually crash the game.

You see if the function that creates the unit is triggered via an event other than map initialization, lets say when he press ESC, then the moment he presses ESC the game will slow and then freezes then at some point will crash.
 
Level 16
Joined
Aug 7, 2009
Messages
1,406
The JNGP JASS syntax checker, as its name says, only searches for syntax errors. The code is correct syntax-wise, but it's an infinite loop; one of the most hated things in the world of programming. I know that it's quite unfortunate, but the syntax checker cannot and is not supposed to protect the user from him/herself.
 
No offense to girls, but I rarely see girls who like programing most of them like to sit in front of a mirror. (I am saying my opinion based on my community, so no offense to anyone)


I've been lurking for 5 minutes searching for an excuse to use this :p

There are /some/ girl programmers here though :eek:

edit
You know what would be a cool feature?
A syntax checker that would reduce the chances of infinite loops by making sure
that there is a return or an exitwhen statement inside a loop/endloop block :D
 
Level 11
Joined
Mar 31, 2009
Messages
732
He means there is no syntax error in the structure of the script but the game don't run because this function run at map initialization; meaning after the loading is done. The function create infinite units which will eventually crash the game.

You see if the function that creates the unit is triggered via an event other than map initialization, lets say when he press ESC, then the moment he presses ESC the game will slow and then freezes then at some point will crash.

Yeah thanks. I got that.
 
Status
Not open for further replies.
Top