Noob Jass Questions

Status
Not open for further replies.

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
Are you trying to make a local out of a global? That's what you've done there. I think you can declare it all together since it's an array, though:

JASS:
local string array udg_playercolor


Then you have to set the indexes.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Well, there is no possible way to create globals without the variable editor that have to have "udg_" in front of it, unless you add a global block in the map's script with "udg_" in front of it as the name.

Also, local strings and arrays are different. You must do what Ghan_04 said. But, the cool thing about locals is that you need no prefix, so a global would be "udg_fart" and the local would be "fart". Unless you add "udg_" in the variable name. :)
 
H

Hjalle

Guest
I tried with this function:

JASS:

function InitColourCodes takes nothing returns nothing
    local string array udg_color
    
    udg_color [0] = "|cffff0000"
    udg_color [1] = "|cff0000ff"
    //Going to add more colour codes, one for each player.
endfunction

But i get this error:
Code:
Line 4: Syntax Error

Can you please tell me what i am really doing wrong?
I want some global color codes that i can use when displaying text.

Just too add, you guys have helped me alot about JASS by now, i really apprieciate (spelling?) that :)

EDIT:
I think i fixed, but now comes another problem -.-...

First, in the map header i have this function:
JASS:
function InitColorCodes takes nothing returns nothing
    local string array udg_color
    
    set udg_color[0] = "|cffff0202"  //RED
    set udg_color[1] = "|cff0041ff"  //BLUE
    set udg_color[2] = "|cff1be5b8"  //CYAN
    set udg_color[3] = "|cff530080"  //PURPLE
    set udg_color[4] = "|cfffffc00"  //YELLOW
    set udg_color[5] = "|cfffe890d"  //ORANGE
    set udg_color[6] = "|cff1fbf00"  //GREEN
    set udg_color[7] = "|cffe45aaf"  //PINK
endfunction

It gives me no errors, and i call the function in a trigger that runs on 0 secs.

Well, then back to my Revive Trigger.
Currently it look like this:

JASS:
function If_Hero takes nothing returns boolean
    if( not( IsUnitType( GetTriggerUnit() , UNIT_TYPE_HERO ) == true ) ) then
        return false
    endif
    return true
endfunction

function Revive_Hero takes nothing returns nothing
    local real X = GetUnitX( GetTriggerUnit() )
    local real Y = GetUnitY( GetTriggerUnit() ) 
    local player killer = GetOwningPlayer( GetKillingUnit() )
    local player victim = GetOwningPlayer( GetTriggerUnit() )
    local integer bonusgold = GetRandomInt( 40, 60 )
    call AddGold( killer, bonusgold )
    call DisplayTextToForce( GetPlayersAll(), udg_color[GetPlayerId( killer )] + (GetPlayerName( killer )) + "|r have just killed " + udg_color[GetPlayerId( victim )] + (GetPlayerName( victim )) + "|r for another |cffffcc00" + I2S(bonusgold) + "|r gold!" )
    call TriggerSleepAction( 10.00 )
    call ReviveHeroLoc( GetTriggerUnit(), OffsetLocation( GetRectCenter( GetEntireMapRect() ), X, Y ), true )
endfunction

//===========================================================================
function InitTrig_TRevive takes nothing returns nothing
    set gg_trg_TRevive = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_TRevive, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_TRevive, Condition( function If_Hero ) )
    call TriggerAddAction( gg_trg_TRevive, function Revive_Hero )
endfunction


The line where i add my text is the one with the error:
Code:
Expected a name
What is wrong with it, please help.
 

SFilip

Gone but not forgotten
Reaction score
634
Well that InitColorCodes function basically does nothing - you declare a local array which is cleaned up after the function ends.
You need to define a global variable in order to access it from other functions.
 
H

Hjalle

Guest
I know, but isn't it a gloabal variable? Since it has udg_ in front of name?

Im a noob, i have no ideas at all how to create and declare globals.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
You can't refer to a global variable without creating it at first. In order to create a global variable you must to one of those two options:

1) Click on Ctrl + B and create the variable regulary

2) You can go to the map header (where there is TFT icon, and by it the map's name .w3x (*.w3x)) and do this:

JASS:

globals
// create globals
endglobals


I might be wrong, I rarely use globals, but from what I remember, this is how you do it.
 

SFilip

Gone but not forgotten
Reaction score
634
Globals cannot be added though code unless you use JassHelper.
So the variable editor is the only way.
 
H

Hjalle

Guest
Ok, i do it the normal way then, simple and good :)
Thanks again for helping.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
JASS:

globals
// create globals
endglobals


I might be wrong, I rarely use globals, but from what I remember, this is how you do it.

That is what I thought too, but I tested it and it doesn't work. This is proof:
Code:
Enter map-specific custom script code below.  [B]This text will be included in the map script [U][I]after variables are declared[/I][/U][/B] and before any trigger code.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
> Globals cannot be added though code unless you use JassHelper.

What if you modified the .j file?
 
H

Hjalle

Guest
Hmm, got another question, im trying to create a leaderboard and add all players from 0 to 9 (10 players) but i end up getting error. This is what i am trying with:

JASS:
function Trig_Leader_Func001Func001C takes nothing returns boolean
    if ( not ( GetPlayerSlotState(ConvertedPlayer(GetForLoopIndexA())) == PLAYER_SLOT_STATE_PLAYING ) ) then
        return false
    endif
    if ( not ( GetPlayerController(ConvertedPlayer(GetForLoopIndexA())) == MAP_CONTROL_USER ) ) then
        return false
    endif
    return true
endfunction

function Create_Leaderboard takes nothing returns nothing
    local integer lop = 0
    call CreateLeaderboardBJ( GetPlayersAll(), "" )
    call LeaderboardDisplay( GetLastCreatedLeaderboard(), true )
    loop
        exitwhen lop > 9
        if ( Trig_Leader_Func001Func001C() ) then
            call LeaderboardAddItemBJ( Player( lop ), GetLastCreatedLeaderboard(), ( udg_color[GetPlayerId(Player(lop)) + GetPlayerName(Player(lop)) + "|r" ),0 ) 
        else
        endif
        set lop = lop + 1
    endloop
    call LeaderboardSortItemsByValue( GetLastCreatedLeaderboard(), true )
    set udg_board = GetLastCreatedLeaderboard()
endfunction

In JassCraft i get this errors:
Code:
Line 23: Bad Types For Binary Operator
Line 23: Bad Types For Binary Operator (2 of those :P)
Line 23: syntax error

Line 23 is the line where i use "call LeaderboardAddItemBJ(....)".
I can't seem to figure out whats wrong.

Does someone know whats wrong?

(ps. my second day with JASS comes to an end. Going sleep now. :p)
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Hm... I think that "udg_color" is unknown to JASSCraft so it might of got the wrong idea and think that the concatenate was the problem or something. Test it out in WE because JASSCraft syntaxes unknown globals. :)
 

Sim

Forum Administrator
Staff member
Reaction score
534
You never end your array.

"[" needs his friend "]" in order to work ;)

Insert it after "GetPlayerId(Player(lop))"
 

SFilip

Gone but not forgotten
Reaction score
634
Time to close this, please make one thread per question (or put several in the first post, but don't add new questions to the same thread). Topics like this quickly lose readability.
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top