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

get integer number Vjass

Level 5
Joined
Nov 3, 2018
Messages
80
I'm working on a thing with a talent system (i'm a gui user) how do i get the number of a integervariable?
JASS:
        method GetTalentPoints takes nothing returns integer
            return GetPlayerState(this.ownerPlayer, PLAYER_STATE_RESOURCE_LUMBER)
        endmethod

        method SetTalentPoints takes integer points returns nothing
            call SetPlayerState(this.ownerPlayer, PLAYER_STATE_RESOURCE_LUMBER, points)

this is what currently is there which gets the ammount of lumber the player has how would the appropiate code be so it checks for an integer number instead of the player wood? probably a noobie question but im really new to vjass and i googled a lot
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,550
An Integer number... So like an Integer variable? Or something specific to the game that isn't user generated? Remember that Jass and GUI are practically the same thing, so all of the GUI concepts you're familiar with exist in Jass as well, just by a different name and in a less familiar form.

Here's some Jass code showcasing some basic variable usage and how you can create your own functions:
vJASS:
library ExampleCode initializer ExampleInit

// Create your variables in between the words globals and endglobals
 globals
     integer SomeInteger = 100
     integer array PlayerIntegerArray
 endglobals

// Call this function and put a Player in the (parameters) to get the value of their Integer variable
 function GetPlayerInteger takes player p returns integer
     return PlayerIntegerArray[GetPlayerId(p)]
 endfunction

// Call this function and put a Player's number (also known as Id) in the (parameters) to get the value of their Integer variable
 function GetPlayerIntegerById takes integer playerId returns integer
     return PlayerIntegerArray[playerId]
 endfunction

// The library knows to run this function during map initialization
 function ExampleInit takes nothing returns nothing
    // Lets define different starting values for our array:
    set PlayerIntegerArray[0] = 100 // For Player 1
    set PlayerIntegerArray[1] = 500 // For Player 2
    set PlayerIntegerArray[2] = 3500 // For Player 3
 endfunction

endlibrary
This code showcases how you could create a normal Integer variable and an Integer array variable. It also shows the basic idea of setting up this data and getting it from one of your own functions.

Notes:
  • In Jass a Player's Player Number actually starts at 0, so Player 1 (Red) has the Player Number of 0, Blue = 1, Teal = 2, etc. If that's confusing, you can use the GetConvertedPlayerId() function to get the GUI player number which starts at 1.
  • The greyed out text in front of the two slashes // is a comment. It's not actual code and is simply there to leave yourself notes and explain things.
  • You can reference all of these variables directly without the need of the two GetPlayerInteger() functions that I made. They're just there to help you.
vJASS:
function SomeOtherFunction takes nothing returns nothing
    // Let's add 100 to our variable:
    set SomeInteger = SomeInteger + 100
endfunction
 
Last edited:
Level 5
Joined
Nov 3, 2018
Messages
80
An Integer number... So like an Integer variable? Or something specific to the game that isn't user generated? Remember that Jass and GUI are practically the same thing, so all of the GUI concepts you're familiar with exist in Jass as well, just by a different name and in a less familiar form.

Here's some Jass code showcasing some basic variable usage and how you can create your own functions:
vJASS:
library ExampleCode initializer ExampleInit

// Create your variables in between the words globals and endglobals
 globals
     integer SomeInteger = 100
     integer array PlayerIntegerArray
 endglobals

// Call this function and put a Player in the (parameters) to get the value of their Integer variable
 function GetPlayerInteger takes player p returns integer
     return PlayerIntegerArray[GetPlayerId(p)]
 endfunction

// Call this function and put a Player's number (also known as Id) in the (parameters) to get the value of their Integer variable
 function GetPlayerIntegerById takes integer playerId returns integer
     return PlayerIntegerArray[playerId]
 endfunction

// The library knows to run this function during map initialization
 function ExampleInit takes nothing returns nothing
    // Lets define different starting values for our array:
    set PlayerIntegerArray[0] = 100 // For Player 1
    set PlayerIntegerArray[1] = 500 // For Player 2
    set PlayerIntegerArray[2] = 3500 // For Player 3
 endfunction

endlibrary
This code showcases how you could create a normal Integer variable and an Integer array variable. It also shows the basic idea of setting up this data and getting it from one of your own functions.

Notes:
  • In Jass a Player's Player Number actually starts at 0, so Player 1 (Red) has the Player Number of 0, Blue = 1, Teal = 2, etc. If that's confusing, you can use the GetConvertedPlayerId() function to get the GUI player number which starts at 1.
  • The greyed out text in front of the two slashes // is a comment. It's not actual code and is simply there to leave yourself notes and explain things.
  • You can reference all of these variables directly without the need of the two GetPlayerInteger() functions that I made. They're just there to help you.
vJASS:
function SomeOtherFunction takes nothing returns nothing
    // Let's add 100 to our variable:
    set SomeInteger = SomeInteger + 100
endfunction
thank you so much! yeah transition from gui to jass feels harsh even though its the same code
assuming i already had my variable set (with another trigger)
basically i got a trigger that detects when a specific hero levels up
JASS:
function Trig_GiveHeroTalentPoin_Copy_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == GetUnitTypeId(udg_Hero) ) ) then
        return false
    endif
    return true
endfunction

function Trig_GiveHeroTalentPoin_Copy_Actions takes nothing returns nothing
    set udg_LEVELINTEGER = ( udg_LEVELINTEGER + 1 )
endfunction

//===========================================================================
function InitTrig_GiveHeroTalentPoin_Copy takes nothing returns nothing
    set gg_trg_GiveHeroTalentPoin_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_GiveHeroTalentPoin_Copy, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddCondition( gg_trg_GiveHeroTalentPoin_Copy, Condition( function Trig_GiveHeroTalentPoin_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_GiveHeroTalentPoin_Copy, function Trig_GiveHeroTalentPoin_Copy_Actions )
endfunction

so when the hero levels up it increases the number of the "LEVELINTEGER" variable so for the code to check the value of that integer
it would need to be something like

function LEVELINTEGER takes player p returns integer
right?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,550
it would need to be something like

function LEVELINTEGER takes player p returns integer
right?
Yes, but you don't need a function to modify or get a variable. You can reference them directly just like you do in GUI. A "get" function serves as a way to run some additional logic before getting your variable.

Here's an example of how you could get your talent system started:
vJASS:
library TalentSystem initializer TalentInit

    // Create your variables in between the words globals and endglobals
    globals
        integer array TalentPoints // This array contains the number of talent points each player has
    endglobals

    // Call this function and put a Player in the (parameters) to get their total talent points
    function GetTalentPoints takes player p returns integer
        return TalentPoints[GetPlayerId(p)]
    endfunction

    function AddTalentPoint takes player p returns nothing
        local integer id = GetPlayerId(p)
        set TalentPoints[id] = TalentPoints[id] + 1
    endfunction

    function SubtractTalentPoint takes player p returns nothing
        local integer id = GetPlayerId(p)
        set TalentPoints[id] = TalentPoints[id] - 1
    endfunction

    function HeroLeveledUpCallback takes nothing returns nothing
        local player p = GetOwningPlayer(GetTriggerUnit())
        call AddTalentPoint(p)
        set p = null
    endfunction

    // The library automatically runs this function during map initialization
    function TalentInit takes nothing returns nothing
        // Create a trigger which adds a talent point when a hero levels up
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_HERO_LEVEL)
        call TriggerAddAction(t, function HeroLeveledUpCallback)
        set t = null
    endfunction

endlibrary
This creates a trigger during map initialization which detects when a hero levels up and adds +1 talent point to it. It also has functions to Add, Subtract, and Get talent points for any given Player.

The GetTalentPoints function takes a Player, then gets their Player Id (known as their Player Number in GUI), and uses that as the [index] of the TalentPoints variable. This returns that variable's value back to wherever you were calling it. So you could do something like this:
vJASS:
local player p = Player(0) // This is Player 1 (Red)
local integer talentPoints = GetTalentPoints(p)
The local variable talentPoints will be set to the total number of talent points that Player 1 (Red) has.
 
Last edited:
Level 5
Joined
Nov 3, 2018
Messages
80
Yes, but you don't need a function to modify or get a variable. You can reference them directly just like you do in GUI. A "get" function serves as a way to run some additional logic before getting your variable.

Here's an example of how you could get your talent system started:
vJASS:
library TalentSystem initializer TalentInit

    // Create your variables in between the words globals and endglobals
    globals
        integer array TalentPoints // This array contains the number of talent points each player has
    endglobals

    // Call this function and put a Player in the (parameters) to get their total talent points
    function GetTalentPoints takes player p returns integer
        return TalentPoints[GetPlayerId(p)]
    endfunction

    function AddTalentPoint takes player p returns nothing
        local integer id = GetPlayerId(p)
        set TalentPoints[id] = TalentPoints[id] + 1
    endfunction

    function SubtractTalentPoint takes player p returns nothing
        local integer id = GetPlayerId(p)
        set TalentPoints[id] = TalentPoints[id] - 1
    endfunction

    function HeroLeveledUpCallback takes nothing returns nothing
        local player p = GetOwningPlayer(GetTriggerUnit())
        call AddTalentPoint(p)
        set p = null
    endfunction

    // The library automatically runs this function during map initialization
    function TalentInit takes nothing returns nothing
        // Create a trigger which adds a talent point when a hero levels up
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_HERO_LEVEL)
        call TriggerAddAction(t, function HeroLeveledUpCallback)
        set t = null
    endfunction

endlibrary
This creates a trigger during map initialization which detects when a hero levels up and adds +1 talent point to it. It also has functions to Add, Subtract, and Get talent points for any given Player.

The GetTalentPoints function takes a Player, then gets their Player Id (known as their Player Number in GUI), and uses that as the [index] of the TalentPoints variable. This gets the player's total talent points which is finally returned back to wherever you were calling it. So you could do something like this:
vJASS:
local player p = Player(0) // This is Player 1 (Red)
local integer talentPoints = GetTalentPoints(p)
The local variable talentPoints will be set to the total number of talent points that Player 1 (Red) has.
i managed to make it work , thank you so so much! <3
 
Top