Noob Jass Questions

Status
Not open for further replies.

Ghan

Administrator - Servers are fun
Staff member
Reaction score
889
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
889
> 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.
  • 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

      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