• 🏆 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] Library problems

Status
Not open for further replies.
Level 30
Joined
Dec 6, 2007
Messages
2,228
Hello there!

Here's my library:

JASS:
library Init
function InitTrig_GSystem takes nothing returns nothing    
    local integer i
    local group g
    local unit u
    local real x
    local real y
    set g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, Player(1),null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        call GroupRemoveUnit(g,u)
        set i = (i+1)
        call SetUnitUserData(u,i)
        set x = GetUnitX(u)
        set y = GetUnitY(u)
        set udg_Creep_Point[i] = Location(x,y)
    endloop
    call FogEnable(false)
    call FogMaskEnable(false)
    set g = null
    set u = null
endfunction
endlibrary

Everytime i save, i get an error message telling me that the end of the line is somehow missing.

How to solve that?

And if there are any other flaws in there, please report them to me.
I'm a beginner :p
 
Last edited:
Level 17
Joined
Jun 17, 2007
Messages
1,433
It compiles fine for me. The syntax checker in the trigger editor in NewGen will give the impression that your code is severely wrong. However, it will save and run fine, so there isn't a worry.

A few tips:

JASS:
set x = GetUnitX(u)
set y = GetUnitY(u)
set udg_Creep_Point[i] = Location(x,y)
Can easily optimize into:

JASS:
set udg_Creep_Point[i] = Location(GetUnitX(u),GetUnitY(u))
Without the need for any x or y variables. Also, since your converting coordinates to a location, it seems like a waste to use them in the first place:

JASS:
set udg_Creep_Point[i] = GetUnitLoc(u)
 
Level 18
Joined
Oct 18, 2007
Messages
930
Oh dear, Paladon using vJass. This is worse that I thought.

Well nvm that.

Here is a fix for all your troubles :)
JASS:
// Super simple library that sets the time of the day and displays a message :)
library TestMapSystems initializer Init
    globals
        private constant real TimeOfDay = 0.0
        private constant string WelcomeMessage = "TestMapSystems v 1.0"
    endglobals
    
    private function Init takes nothing returns nothing
        call BJDebugMsg(WelcomeMessage)
        call SetFloatGameState(GAME_STATE_TIME_OF_DAY, TimeOfDay)
        call FogMaskEnable(false)
        call FogEnable(false)
    endfunction
endlibrary

// Simple TreeRespawn system
library TreeRespawn initializer Init

    globals
        private constant real Time = 20.
        
        private trigger Act
    endglobals
    
    private function W2D takes widget w returns destructable
        return w
        return null
    endfunction

    private function Actions takes nothing returns nothing
        local destructable Tree = W2D(GetTriggerWidget())
        local real X = GetWidgetX(Tree)
        local real Y = GetWidgetY(Tree)
        local real L = GetWidgetLife(Tree)
            
        call TriggerSleepAction(Time)
            
        call DestructableRestoreLife(Tree, L, true)
            
        set Tree = null
    endfunction
        
    private function Filter takes nothing returns nothing
        local destructable d = GetEnumDestructable()
        call TriggerRegisterDeathEvent(Act, d)
        set d = null
    endfunction

    private function Init takes nothing returns nothing
        set Act = CreateTrigger()
        call TriggerAddAction(Act, function Actions)
        set bj_wantDestroyGroup = true
        call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function Filter)
    endfunction
endlibrary

// Simple Unit Revive System for a player
library ReviveSystem initializer Init

    globals
        private constant player P = Player(PLAYER_NEUTRAL_AGGRESSIVE)
        
        private constant real Time = 60. //Sec.
        private constant real Life = 100. //%
        private constant real Mana = 50. //%
            
        private integer array T // Type
        private real array X // X
        private real array Y // Y
        private real array F // Facing
    endglobals

    private function Conditions takes nothing returns boolean
        return IsUnitAlly(GetTriggerUnit(), P) == true and GetUnitUserData(GetTriggerUnit()) > 0
    endfunction

    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer i = GetUnitUserData(u)
            
        call TriggerSleepAction(Time)
        
        call RemoveUnit(u)

        set u = CreateUnit(P, T[i], X[i], Y[i], F[i])
        call SetUnitUserData(u, i)
            
        call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_MAX_LIFE) * Life * 0.01)
        call SetUnitState(u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MAX_MANA) * Mana * 0.01)
            
        set u = null
    endfunction

//===========================================================================
    private function SetupFilter takes nothing returns boolean
        return IsUnitAlly(GetFilterUnit(), P)
    endfunction

    private function Init takes nothing returns nothing
        local trigger trg = CreateTrigger()
        local group g = CreateGroup()
        local unit u
        local integer i = 1
        call TriggerRegisterAnyUnitEventBJ( trg, EVENT_PLAYER_UNIT_DEATH )
        call TriggerAddCondition( trg, Condition( function Conditions ) )
        call TriggerAddAction( trg, function Actions )

        call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Condition(function SetupFilter))
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
                
            set T[i] = GetUnitTypeId(u)
            set X[i] = GetUnitX(u)
            set Y[i] = GetUnitY(u)
            set F[i] = GetUnitFacing(u)
            call SetUnitUserData(u, i)
                
            set i = i + 1
            call GroupRemoveUnit(g, u)
        endloop

        call DestroyGroup(g)
        set trg = null
        set g = null
    endfunction

endlibrary
 
Level 9
Joined
Apr 5, 2008
Messages
529
What version of JNGP/JassHelper are you using?

Here's a few tips:

1. Use library initializers instead. There's not reason for this, I just think everyone should get used to it.
2. The script won't work, you declare a local integer with no initial value, so when you set the variable to +1, the thread will crash, because of the missing initial value.
3. Passing a "null" parameter to boolexpr's will leak. BoolexprUtils,
4. You forget to destroy the group.
5. No need to nullify the unit variable.

Hope these helped a little, =]
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Save it twice. You should see JassHelper kicking in when the script is compiling.
If not, check that the JNGP is located on the same partition as your saved file. It seems to have caused several problems to me.
 
Level 4
Joined
Feb 2, 2009
Messages
71
I am often experiencing the same problem (Wc3 menu shows up when testing) but it always goes away after saving once again.
 
Level 14
Joined
Nov 23, 2008
Messages
187
Hmm, I have the same problem, when I tried to save map with russian symbols, and with too long name. Save your map to e.g. "C:\123.w3x", save again and see, what happens when you press "Test map" button.

Also, make sure that you haven't disabled vJass syntax (but, according to previous posts, I doubt that is disabled).
 
Level 30
Joined
Dec 6, 2007
Messages
2,228
Did not work.

And that would not explain why the map (and vJass) works for everyone else.

EDIT: I am stupid. It was simple. Nothing more, it is finally
140841-albums879-picture9821.png
 
Last edited:
Level 23
Joined
Nov 29, 2006
Messages
2,482
Nope, I already said that to him, since he was using v1.21b at first. So I gave him that tip and he changed the path... but it didn't work

A good tip tho .-. and a weird problem even if he got it fixed now.
 
Status
Not open for further replies.
Top