I2S won't work without calling it from another function

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
I'm using I2S to display the integer "runnerCount". For some reason, it won't work if I don't retrieve the value through a function. It also won't work if use I2S(getRunnerCount()).

Library
JASS:

library Initialization initializer Init

    globals
        force forceRunners
        force forceTaggers
        integer runnerCount
        integer taggerCount
    endglobals
    
    function getRunnerCount takes nothing returns integer
        return runnerCount
    endfunction
    
    function getTaggerCount takes nothing returns integer
        return taggerCount
    endfunction
    
    private function Init takes nothing returns nothing
        local integer counter = 0
        local player p
        
        loop
        exitwhen counter > 11
            set p = Player(counter)
            if (GetPlayerController(p)== MAP_CONTROL_USER) and (GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING) then
                call ForceAddPlayer(forceRunners, p)
                set runnerCount = runnerCount + 1
            endif
            set counter = counter + 1
        endloop
    endfunction
        
endlibrary


Works
JASS:

scope Test initializer Init

    private function Actions takes nothing returns nothing
        if (getRunnerCount > 1) then
            call BJDebugMsg("There are " + I2S(getRunnerCount) + " runners remaining.")
        else
            call BJDebugMsg("There is " + I2S(getRunnerCount) + " runner remaining.")
        endif
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local player p
        local integer counter = 0
        
        call TriggerAddAction(t, function Actions)
        loop
        exitwhen counter > 11
            set p = Player(counter)
            call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_END_CINEMATIC)
            set counter = counter + 1
        endloop
    endfunction
    
endscope


Does not work
JASS:

scope Test initializer Init

    private function Actions takes nothing returns nothing
        if (runnerCount > 1) then
            call BJDebugMsg("There are " + I2S(runnerCount) + " runners remaining.")
        else
            call BJDebugMsg("There is " + I2S(runnerCount) + " runner remaining.")
        endif
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local player p
        local integer counter = 0
        
        call TriggerAddAction(t, function Actions)
        loop
        exitwhen counter > 11
            set p = Player(counter)
            call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_END_CINEMATIC)
            set counter = counter + 1
        endloop
    endfunction
    
endscope
 

Flare

Stops copies me!
Reaction score
662
You can't add 1 to an undefined value :X

Initialize those variables to a value (0 would appear to be the only logical initial value for those integers, and [ljass]CreateForce ()[/ljass] for those force variables)

Code:
if ([B]getRunnerCount[/B] > 1) then
Syntax-wise, this would be attempting to refer to a variable - functions require (parameters) after the name when calling, even if there are no parameters
JASS:
if getRunnerCount () > 1 then

is what it should be
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
Oh, thanks a bunch. I have no idea why they don't say those sort of things in the tutorials.
 

Jesus4Lyf

Good Idea™
Reaction score
397
For more detail:
JASS:
if (getRunnerCount > 1) then

That is not calling the function, as was said. It is referring to the function as an object (function pointer, basically) and implicitly typecasting it into an integer, and checking that the integer is greater than 1. :)

>Initialize those variables to a value (0 would appear to be the only logical initial value for those integers, and CreateForce () for those force variables)
Very important, referring to unitialised variables crashes the thread. ;)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top