JASS Classroom, Lesson I

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Well, I got only 3 planned lessons, and each is one is almost as lengthy as a normal tutorial would be...
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
Is it impossible to use ctrl C and V in Jasscraft search function?
It gave an error.

edit: oO i didn't find anything for
Code:
SetUnitLife
ModifyHeroStat

in JAsscraft oO just the BJ functions... oO
 

mase

____ ___ ____ __
Reaction score
154
My 'mini-tests' are attached ><
 

Attachments

  • JASS I.txt
    1.7 KB · Views: 246

uberfoop

~=Admiral Stukov=~
Reaction score
177
edit: oO i didn't find anything for
Code:
SetUnitLife
ModifyHeroStat

in JAsscraft oO just the BJ functions... oO
Code:
native          SetUnitState        takes unit whichUnit, unitstate whichUnitState, real newVal returns nothing
Unit state can be like, UNIT_STATE_MANA or UNIT_STATE_LIFE
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
thanks!

oO this line doesn't work!!!!!!11111111111111

Code:
    native SetPlayerState   takes player TriggPlayer, gold whichPlayerState, ( TriggPlayer_Gold +  R2I(TriggUnit_MaxLife)) value returns nothing

code-order needed... please help...
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
I declare lesson I finished. Here are the 3 sent assignments.

My solution to the assignment.

JASS:
function ReplenishHero takes unit whichHero returns nothing
    local real    health = GetUnitState( whichHero, UNIT_STATE_MAX_LIFE )
    local real    mana   = GetUnitState( whichHero, UNIT_STATE_MAX_MANA )
    local player  p      = GetOwningPlayer(whichHero)
    local integer random = GetRandomInt( 0, 2 )
    
    if ( IsUnitType( whichHero, UNIT_TYPE_HERO ) == true ) then
        call SetUnitState( whichHero, UNIT_STATE_LIFE, health )
        call SetUnitState( whichHero, UNIT_STATE_MANA, mana )
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD ) + R2I(health) )
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER ) + R2I(mana) )
        if     ( random == 0 ) then
            call SetHeroAgi( whichHero, GetHeroAgi( whichHero, true ) + 1, true )
        elseif ( random == 1 ) then
            call SetHeroInt( whichHero, GetHeroInt( whichHero, true ) + 1, true )
        elseif ( random == 2 ) then
            call SetHeroStr( whichHero, GetHeroStr( whichHero, true ) + 1, true )
        endif
    endif
    
    set p = null
endfunction


Doom-Angels solution,

JASS:
function assignment takes unit u returns nothing
    local real    l = GetUnitState( u,UNIT_STATE_MAX_LIFE )
    local real    m = GetUnitState( u,UNIT_STATE_MAX_MANA )
    local integer r = GetRandomInt( 1, 3 )
    
    //if ( IsUnitType( u, UNIT_TYPE_HERO ) == true ) then
        call SetUnitState( u,UNIT_STATE_LIFE, l )
        call SetUnitState( u,UNIT_STATE_MANA, m )
        call SetPlayerState( GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, R2I(l) )
        call SetPlayerState( GetOwningPlayer(u), PLAYER_STATE_RESOURCE_LUMBER, R2I(m) )
        if     (r == 1) then
            call SetHeroStr(u,( GetHeroStr( u, false ) + 1 ), true )
        elseif (r == 2) then
            call SetHeroAgi(u,( GetHeroAgi( u, false ) + 1 ), true )
        elseif (r == 3) then
            call SetHeroInt(u,( GetHeroInt( u,false ) + 1 ), true )
        endif
    //endif
endfunction


Good Job. That is almost perfect. Only thing You forgot, was to check whether the unit is a hero.

Substances
solution,

JASS:
function IsUnitHero takes nothing returns boolean
    if IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true then
        return true
    endif
    return false
    
    // return (IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true)
endfunction

function Assignment takes nothing returns nothing
    local player   p = GetTriggerPlayer()
    local boolexpr b = Condition(function IsUnitHero)
    
    // GetUnitsOfPlayerMatching =&gt;
    // local group    g = CreateGroup()
    // local boolexpr f = Condition( function IsUnithero )
    // call GroupEnumUnitsOfPlayer( g, p, f )
    local group    g = GetUnitsOfPlayerMatching(p,b)
    local integer  i = GetRandomInt(1,3)
    local unit     u
    
    //Unneeded, explained below.
    local integer array id
    set id[1]= bj_HEROSTAT_STR
    set id[2]= bj_HEROSTAT_AGI
    set id[3]= bj_HEROSTAT_INT
    
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call SetUnitState( u, UNIT_STATE_MANA, GetUnitState( u, UNIT_STATE_MAX_MANA ) )
        call SetUnitState( u, UNIT_STATE_LIFE, GetUnitState( u, UNIT_STATE_MAX_LIFE ) )
        call SetPlayerState( p,PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD ) + R2I(GetUnitState( u, UNIT_STATE_LIFE )) )
        call SetPlayerState( p,PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER ) + R2I(GetUnitState( u, UNIT_STATE_MANA )) )
        
        // ModifyHeroStat is a BJ. No arrays needed. To make it random. =&gt;
        // if     ( i == 0 ) then
        //     call SetHeroAgi( u, GetHeroAgi( u, true ) + 1, true )
        // elseif ( i == 1 ) then
        //     call SetHeroInt( u, GetHeroInt( u, true ) + 1, true )
        // elseif ( i == 2 ) then
        //     call SetHeroStr( u, GetHeroStr( u, true ) + 1, true )
        // endif
        call ModifyHeroStat( id<i>, u, id<i>, 1 )
        call GroupRemoveUnit(g,u)
        
        // &quot;Set u = null&quot; should be outside of the loop.
        set u = null
    endloop
endfunction</i></i>


The code should have been in one single function. In addition, I said the function takes a hero(an unit), so the looping procedure to find the unit is unnecessary.

IKilledKennys
solution,

JASS:
function act takes nothing returns nothing
    local group   grouped   = CreateGroup()
    local unit    picked
    local integer forloop   = 0
    local real    maxhealth
    local real    maxmana
    local integer gold
    local integer lumber
    local integer attribute
    local integer attbase
    local player  owner
    
    call GroupEnumUnitsInRect( grouped, GetWorldBounds(), null )
    loop
        set picked = FirstOfGroup(grouped) 
        //exitwhen ( IsUnitType( picked, UNIT_TYPE_HERO ) == true ) 
        exitwhen forloop == 1
        if IsUnitType(picked,UNIT_TYPE_HERO)==true then
            set forloop=1
        endif
        call GroupRemoveUnit(grouped,picked)
    endloop
    call DestroyGroup(grouped)
    
    set owner     = GetOwningPlayer(picked)
    set maxhealth = GetUnitState( picked,UNIT_STATE_MAX_LIFE )
    call SetUnitState( picked,UNIT_STATE_LIFE, maxhealth )
    set maxmana   = GetUnitState(picked,UNIT_STATE_MAX_MANA)
    call SetUnitState( picked, UNIT_STATE_MANA, maxmana )
    set gold      = GetPlayerState( owner, PLAYER_STATE_RESOURCE_GOLD )
    call SetPlayerState( owner, PLAYER_STATE_RESOURCE_GOLD, gold + R2I(maxhealth))
    set lumber    = GetPlayerState(owner,PLAYER_STATE_RESOURCE_LUMBER)
    
    //call SetPlayerState( owner, PLAYER_STATE_RESOURCE_LUMBER, lumber + R2I(maxmana))    
    call SetPlayerState( owner, PLAYER_STATE_RESOURCE_LUMBER, gold + R2I(maxmana))
    set attribute = GetRandomInt( 0, 2 )
    
    // GetHeroStatBJ... =&gt;
    // ModifyHeroStat is a BJ. To make it random =&gt;
    // if     ( attribute == 0 ) then
    //     call SetHeroAgi( picked, GetHeroAgi( picked, true ) + 1, true )
    // elseif ( attribute == 1 ) then
    //     call SetHeroInt( picked, GetHeroInt( picked, true ) + 1, true )
    // elseif ( attribute == 2 ) then
    //     call SetHeroStr( picked, GetHeroStr( picked, true ) + 1, true )
    // endif    
    set attbase   = GetHeroStatBJ( attribute, picked, false )
    call SetHeroStat( picked, attribute,( attbase + 1) )
    
    set grouped = null
    set picked  = null
    set owner   = null    
endfunction


You could have used less variables, that is a bit of an overkill. Anyway, no harm done with that. However, I said the function takes a hero(unit) so the procedure to find the unit is unnecessary.

Thanks for everyone, who participated. I hope this was a valueable lesson.:)
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
Almost perfect yay :p

so not much of the pupils made homework (or there weren't as many as i thought there were)

anyway when is the next lesson?
 

substance

New Member
Reaction score
34
The code should have been in one single function. In addition, I said the function takes a hero(an unit), so the looping procedure to find the unit is unnecessary.

Ahh, didnt know it had to be one function. Although, assuming the player had more than a few units it seems the boolean would be more efficient(depending on the event... mine was a player event)

And yes, the loop was incase the player had more than one hero unit =p

**edit, Oh and according to JASSCraft 'bj_HEROSTAT_STR' doesnt call another function... that's why i figured it was ok to use.
 
I

IKilledKEnny

Guest
Ah darn I didn't see you could do a function that takes unit. Oh well.

About the variables, I could have used about half of them, just to make is more readable though I used so many.

About the BJs, I know there are, however the function that they call is simple very long, and putting one or 2 BJs couldn't harm much. Also:

JASS:
if     ( random == 0 ) then
            call SetHeroAgi( whichHero, GetHeroAgi( whichHero, true ) + 1, true )
        elseif ( random == 1 ) then
            call SetHeroInt( whichHero, GetHeroInt( whichHero, true ) + 1, true )
        elseif ( random == 2 ) then
            call SetHeroStr( whichHero, GetHeroStr( whichHero, true ) + 1, true )


Could have been done like this:

JASS:
call SetHeroStat( picked, attribute,( attbase + 1) )


If you would look at the BJ, that what it does, simply shortened into one line.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
anyway when is the next lesson?

Soon enough. I maybe will make into a tutorial with assignments instead.

Although, assuming the player had more than a few units it seems the boolean would be more efficient(depending on the event... mine was a player event)

The assignment is following:

You have to make a function(not functions), which takes a hero typed unit, replenishes all its life- and mana points, gives the owner of the unit as many gold as many hitpoints the hero has plus as many lumber as many mana points the unit has. Also, the hero must receive +1 random attribute stat(str, agi or int).

**edit, Oh and according to JASSCraft 'bj_HEROSTAT_STR' doesnt call another function... that's why i figured it was ok to use.

Yes, but SetHeroStat is a BJ function.:)

Ah darn I didn't see you could do a function that takes unit. Oh well.

The assignment is following:

You have to make a function, which takes a hero typed unit...

:rolleyes:

About the variables, I could have used about half of them, just to make is more readable though I used so many.

Yeh, that is not such of a problem.;)

About the BJs, I know there are, however the function that they call is simple very long, and putting one or 2 BJs couldn't harm much.
If you would look at the BJ, that what it does, simply shortened into one line.

The length of the code itself does not matter. The amount of function calls does.


Anyway, thanks for all who participated.
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
oO shit, i couldn't finish my assignement :eek:
I think i will post it here today.

:(
:(
:(

Just had to many questions oO
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top