• 🏆 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] Few Questions

Status
Not open for further replies.
Level 5
Joined
Nov 22, 2009
Messages
181
and my grandpa just sat down and farted.

ROFLMAO.

thank you guys.

You know how, when you use jass in jngp and you try to test the map you have to save the map first otherwise it will just go straight to the game's main menu? Well, I've tried saving the map like a 14 times and it hasn't worked. What am i doing wrong?

So could you, for example, use GetLocalPlayer() to show a multiboard to one player and one player only?
 
Level 5
Joined
Nov 22, 2009
Messages
181
1: never had it enabled.

when you declare the start of a color code using lc, is the first character a lowercase L or some other symbol?
 
Level 5
Joined
Nov 22, 2009
Messages
181
1: I had disabled it when i first got jngp because i heard about that issue before i got it.

I just deleted all the code and created a trigger (gui form) with the 10 seconds elapsed event and then for the actions I used custom script: call BJDebugMsg("|cffff0000"+"colors"+"c|") and then clicked test map and it worked! the map actually ran. I don't know why it didn't work when I tried to do it all in jass. I never even saved the map.

2: cool thank you
 
Level 5
Joined
Nov 22, 2009
Messages
181
oh it was nothing to trouble over i simply created a new map did nothing to it except put :
JASS:
function display takes string s returns nothing
    call TriggerSleepAction(5.00)
    call BJDebugMsg(s+"color"+"c|")
endfunction
function InitTrig_call takes nothing returns nothing
    call display("|cffff0000")
endfunction
 
Last edited:
Level 5
Joined
Nov 22, 2009
Messages
181
oops typo i did not copy paste directly.

can you have an onCreate method that works the same as onDestroy? and if so can and how would it be used for an array struct? oh and it says the syntax for an array struct is :
JASS:
struct mystruct extends array
is array an interface or another struct, and do i have to declare it or is it a native?
 
For "onCreate" you just use this method inside the struct:
JASS:
static method create takes nothing /*you can take some parameters*/ returns thistype
    local thistype this = thistype.allocate()
   //do stuff
    return this
endmethod

It will basically override the create function. If you add parameters, such as a unit, you would need to use call myStruct.create(GetTriggerUnit()), or well to put it broadly, one with parameters would look like this:
call myStruct.create(param A, param B, param C...) //etc..
 
Level 5
Joined
Nov 22, 2009
Messages
181
but i thought you can't use .allocate or .destroy for array functions it says so specifically on jasshelper. and if you cant use .destroy then how do you destroy the instance if desired?

almost like calling a normal function. i know already.
 
Well, you don't need to create structs that extend arrays.
JASS:
scope WheeXX initializer Init
    private struct Fun extends array
        real x
    endstruct
    private function Init takes nothing returns nothing
        set Fun[0].x = 15
    endfunction
endscope

You just use it directly. StructName[Index].member = value

EDIT: And you can't use .destroy()/.deallocate() for structs that extend arrays.

EDIT2: For your other question, you don't need to really declare them. You can pretty much just use them. They are nice for having struct values for things for players. For example, if you wanted to store each player's agi, str, and intelligence of their main hero, you could just use an array-extended-struct indexed to their player id and store values for each.
 
Level 5
Joined
Nov 22, 2009
Messages
181
so if you can just use it directly then what is the point of .create?. for edit 2, i am using an array extended struct to store player stats and was going to have them indexed to their ids. hmm let me show you what im trying to do.


JASS:
struct stats
    integer k=0
    integer d=0
    integer tfpu=0
    integer tfd=0
    integer tfr=0
    integer tfc=0
    integer tba=0
    integer tbd=0
    integer tbc=0
//Warsong Gulch Stats
    integer wgfpu=0
    integer wgfd=0
    integer wgfr=0
    integer wgfc=0
//Arathi Basin Stats
    integer abba=0
    integer abbd=0
    integer abbc=0
//Alterac Valley Stats
    integer td=0
//Eye of the Storm Stats
    integer esfpu=0
    integer esfd=0
    integer esfc=0
    integer esba=0
    integer esbd=0
    integer esbc=0
//Strand of the Ancients Stats
    integer vu=0
    integer gd=0
endstruct
struct W/L
    integer wgw=0
    integer abw=0
    integer avw=0
    integer esw=0
    integer saw=0
    integer tw=0
    integer wgl=0
    integer abl=0
    integer avl=0
    integer esl=0
    integer sal=0
    integer tl=0
endstruct
struct
struct player extends array
    stats s=0
    W/L w=0
    private boolean IsAlliance = false
    //so can i do this?
    method create takes integer i returns nothing
        set .s = stats.create()
        set .w = W/L.create()
        if i <= 5 then
            set IsAlliance = true
        else
            set IsAlliance = false
    endmethod
    method r takes nothing returns boolean
        return IsAlliance
    endmethod
endstruct
function InitTrig_InitStructs takes nothing returns nothing
    local integer i = 0
        loop
            exitwhen i = 11//does setting Player directly 
            call Player[i].create(i) //make it like a global variable?
            set i = i + 1// and when you declare globals in jass do you
        endloop//still need to put the udg_ prefix in front of it?
endfunction
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
First, you should change the name of those variables to something that actually makes sense, because no one can figure out what the heck you just gave us.

Second, syntax errors:

W/L can't do that. Needs to be WL or wL or something.

method create needs to be static method create.
private boolean inside of a struct that extends an array is not going to help. Change it to "boolean". Every member of a struct is prefixed by default so you can have 40 structs with the members each having the exact same name and you have no problem.

You can't initialize variables in a struct that extends an array. You have to set them within the function itself.

Don't do udg_ or gg_ or any crap like that.
 
Level 5
Joined
Nov 22, 2009
Messages
181
sorry
all of the variables (except the W/L, Alterac valley stat, Strand of the ancients stats, and first 9 stats variables) have the initials of the battleground those stats are for.
fpu= flags picked up
fd = flags dropped
fr = flags returned
fc = flags captured
ba = bases attacked
bd = bases defended
bc = bases captured
t (in front of the variable stands for total)
(battlegroundinitials)W (or l)= (amount of wins/losses they have had for that battleground)

does that make sense?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
Question:

What's the difference between

JASS:
private struct Fun extends array

and

JASS:
private struct array Fun

?

Answer: A syntax error.

the second one gives a syntax error.

However, if you are referring to private structName array arrayName in a globals block, that's fine.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
sorry
all of the variables (except the W/L, Alterac valley stat, Strand of the ancients stats, and first 9 stats variables) have the initials of the battleground those stats are for.
fpu= flags picked up
fd = flags dropped
fr = flags returned
fc = flags captured
ba = bases attacked
bd = bases defended
bc = bases captured
t (in front of the variable stands for total)
(battlegroundinitials)W (or l)= (amount of wins/losses they have had for that battleground)

does that make sense?
Implement those descriptions into the variable names themselves, because when you look at your map again in a few months you're going to wonder what each of those means.
 
Level 5
Joined
Nov 22, 2009
Messages
181
Structing is an art. It's up to you to determine how to implement them. You can do extends array or you can do flat-out arrays and skip the whole struct part.

The main thing to note about "extends array" is that it's mostly used for aesthetic purposes (you type structName[i].variable instead of variable[i]

what do you mean by variable[1]?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
I mean a normal, average, everyday variable.

JASS:
globals
    unit array u
endglobals
function sth takes nothing returns nothing
    set u[0] = bj_lastCreatedUnit
endfunction

Does the same thing as:

JASS:
struct Name extends array
    unit u
endstruct
 
function sth takes nothing returns nothing
    set Name[0].u = bj_lastCreatedUnit
endfunction
 
Level 5
Joined
Nov 22, 2009
Messages
181
What is wrong with this STUPID SCRIPT!!!! for some reason whenever i try to test the map, it just goes straight to the main menu. I don't know what the errors are! and JassHelper isint working. whenever i try to test the map with it enabled, it freezes. IT IS DRIVING ME NUTS!!!!

here it is:
JASS:
globals
    string array ColorCodes
    string StringStart = "|c"
    string StringEnd = "c|"
endglobals
function InitTrig_Strings takes nothing returns nothing
    set CC[1] = "0"
    set CC[2] = "1"
    set CC[3] = "2"
    set CC[4] = "3"
    set CC[5] = "4"
    set CC[6] = "5"
    set CC[7] = "6"
    set CCs[8] = "7"
    set CC[9] = "8"
    set CC[10] = "9"
    set CC[11] = "a"
    set CC[12] = "b"
    set CC[13] = "c"
    set CC[14] = "d"
    set CC[15] = "e"
    set CC[16] = "f"
endfunction
function DisplayColors takes nothing returns nothing
    local integer a1 = 0
    local integer a2 = 0
    local integer r1 = 0
    local integer r2 = 0
    local integer g1 = 0
    local integer g2 = 0
    local integer b2 = 0
    local integer b1 = 0
        call TriggerSleepAction(10.00)
        loop
            exitwhen a1==16
            loop
                exitwhen a2==16
                loop
                    exitwhen r1==16
                    loop
                        exitwhen r2==16
                        loop
                            exitwhen g1==16
                            loop
                                exitwhen g2==16
                                loop
                                    exitwhen b1==16
                                    loop
                                        exitwhen b2==16
                                        call BJDebugMsg(StringStart+CC[a1]+CC[a2]++CC[r1]+CC[r2]+CC[g1]+CC[g2]+CC[b1]+CC[b2]+"color"+StringEnd)
                                        set b2 = b2 + 1
                                    endloop
                                    set b1 = b1 + 1
                                endloop
                                set g2 = g2 + 1
                            endloop
                            set g1 = g1 + 1
                        endloop
                        set r2 = r2 + 1
                    endloop
                    set r1 + r1 + 1
                endloop
                set a2 = a2 + 1
            endloop
            set a1 = a1 + 1
        endloop
endfunction
  • DisplayString
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Custom script: call DisplayColors()
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
JASS:
scope colors initializer Init
globals
    private string array CC
    private string StringStart = "|cff"
    private string StringEnd = "|r"
 
    private integer index = 0
endglobals
 
private function DisplayColors takes nothing returns nothing
    call ClearTextMessages()
    call BJDebugMsg(StringStart+CC[index]+CC[index]+CC[index]+CC[index]+CC[index]+CC[index]+"Use the Force"+StringEnd)
    if index == 15 then
        call DestroyTimer(GetExpiredTimer())
    else
        set index = index + 1
    endif
endfunction
 
private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(),0.2,true,function DisplayColors)
    set CC[0] = "0"
    set CC[1] = "1"
    set CC[2] = "2"
    set CC[3] = "3"
    set CC[4] = "4"
    set CC[5] = "5"
    set CC[6] = "6"
    set CC[7] = "7"
    set CC[8] = "8"
    set CC[9] = "9"
    set CC[10] = "a"
    set CC[11] = "b"
    set CC[12] = "c"
    set CC[13] = "d"
    set CC[14] = "e"
    set CC[15] = "f"
endfunction
endscope
 
Last edited:
Level 5
Joined
Nov 22, 2009
Messages
181
what is the ClearTextMessages() thing for?
and is index actually part of the code? or is it just for me to replace with w/e value or variable i want?
 
Level 5
Joined
Nov 22, 2009
Messages
181
it doesn't seem to be working. and i wanted it so that it uses each combination atleast once. every time i test though, it is almost as if the timer only runs once with the first color being white.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
JASS:
scope colors initializer Init
globals
    private string array CC
    private string StringStart = "|cff"
    private string StringEnd = "|r"
endglobals
 
private function DisplayColors takes nothing returns nothing
    call ClearTextMessages()
    call BJDebugMsg(StringStart+CC[GetRandomInt(0,15)]+CC[GetRandomInt(0,15)]+CC[GetRandomInt(0,15)]+CC[GetRandomInt(0,15)]+CC[GetRandomInt(0,15)]+CC[GetRandomInt(0,15)]+"Use the Force"+StringEnd)
endfunction
 
private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(),0.2,true,function DisplayColors)
    set CC[0] = "0"
    set CC[1] = "1"
    set CC[2] = "2"
    set CC[3] = "3"
    set CC[4] = "4"
    set CC[5] = "5"
    set CC[6] = "6"
    set CC[7] = "7"
    set CC[8] = "8"
    set CC[9] = "9"
    set CC[10] = "a"
    set CC[11] = "b"
    set CC[12] = "c"
    set CC[13] = "d"
    set CC[14] = "e"
    set CC[15] = "f"
endfunction
endscope
 
Level 5
Joined
Nov 22, 2009
Messages
181
thank you but i was thinking of having it in a more systematic fashion like this:

JASS:
scope colors initializer Init
globals
    private string array CC
    private string CStart = "|cff"
    private string CEnd = "|r"
 
    private integer index = 0
endglobals
 
private function DisplayColors takes nothing returns nothing
    local integer r1 = 0
    local integer r2 = 0
    local integer g1 = 0
    local integer g2 = 0
    local integer b1 = 0
    local integer b2 = 0
        loop
            exitwhen r1 == 15
            loop
                exitwhen r2 == 15
                loop
                    exitwhen g1 == 15
                    loop
                        exitwhen g2 == 15
                        loop
                            exitwhen b1 == 15
                            loop
                                exitwhen b2 == 15
                                call BJDebugMsg(CStart+CC[r1]+CC[r2]+CC[g1]+CC[g2]+CC[b1]+CC[b2]+"color"+CEnd)
                                set b2 = b2 + 1
                            endloop
                            set b2 = 0
                            set b1 = b1 + 1
                        endloop
                        set b1 = 0
                        set g2 = g2 + 1
                    endloop
                    set g2 = 0
                    set g1 = g1 + 1
                endloop
                set g1 = 0
                set r2 = r2 + 1
            endloop
            set r2 = 0
            set r1 = r1 + 1
        endloop
endfunction
 
private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(),0.2,false,function DisplayColors)
    set CC[0] = "0"
    set CC[1] = "1"
    set CC[2] = "2"
    set CC[3] = "3"
    set CC[4] = "4"
    set CC[5] = "5"
    set CC[6] = "6"
    set CC[7] = "7"
    set CC[8] = "8"
    set CC[9] = "9"
    set CC[10] = "a"
    set CC[11] = "b"
    set CC[12] = "c"
    set CC[13] = "d"
    set CC[14] = "e"
    set CC[15] = "f"
endfunction
endscope
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
Great if it works (can't test it as the woman is online):

JASS:
library Colours initializer Init
 
globals
    private string array c      //* color slot
    private integer array m     //* index slot for each column
 
    private integer col  = 1    //* minor column
    private integer row  = 0    //* minor row
    private integer main = 0    //* main column
    private integer mRow = 0    //* main row
endglobals
 
    private function Display takes nothing returns nothing
        local integer i
 
//*
//* Loop vertically through rows:
//*
        set m[col]= row
        set row = row +1
        if row > 15 then
            set row = 0
            set col = col +1
//*
//* The main column gets skipped:
//*
            if col == main then
                set col = col +1
            endif
 
            set i = 0
            loop
                if i != main then
                    set m[i] = 0
                endif
                exitwhen i == 5
                set i = i +1
            endloop
 
            if col > 5 then
                set col = 0
                set mRow = mRow +1
                if mRow > 15 then
                    set mRow = 0
                    set main = main +1
                    if main > 5 then
                        call PauseTimer(GetExpiredTimer())
                        call DestroyTimer(GetExpiredTimer())
                    endif
                endif
                set m[main] = mRow
            endif
        endif
        call BJDebugMsg("|cff"+c[m[0]]+c[m[1]]+c[m[2]]+c[m[3]]+c[m[4]]+c[m[5]]+"|r")
    endfunction
 
    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(),0.04,false,function Display)
        set m[0] = 0
        set m[1] = 0
        set m[2] = 0
        set m[3] = 0
        set m[4] = 0
        set m[5] = 0
 
        set c[0] = "0"
        set c[1] = "1"
        set c[2] = "2"
        set c[3] = "3"
        set c[4] = "4"
        set c[5] = "5"
        set c[6] = "6"
        set c[7] = "7"
        set c[8] = "8"
        set c[9] = "9"
        set c[10] = "a"
        set c[11] = "b"
        set c[12] = "c"
        set c[13] = "d"
        set c[14] = "e"
        set c[15] = "f"
    endfunction
 
endlibrary
 
Last edited:
Level 5
Joined
Nov 22, 2009
Messages
181
what would the booleans be for? what is the row and column thing for? im not making a multiboard. i just want to use it to see exactly which colors i want to use in my real map. what is a comprehensive integer-variable array?

i would think i only need the 6 exitwhen conditions which are already boolean and already in the example.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
It hadn't occurred to me that you could just check the message log, so I thought you had to see the message as it was happening.

lolllll.

Well, technically the message log is having limits as to how much it can display, so the best method is probably just to watch it as it goes.

Well this generates almost all of the colors, at least:

JASS:
library Colours initializer Init
 
globals
    private string array c      //* color slot
    private integer array m     //* index slot for each column
 
    private integer col  = 1    //* minor column
    private integer row  = 0    //* minor row
    private integer main = 0    //* main column
    private integer mRow = 0    //* main row
endglobals
 
    private function Display takes nothing returns nothing
        local integer i
        call BJDebugMsg("|cff"+c[m[0]]+c[m[1]]+c[m[2]]+c[m[3]]+c[m[4]]+c[m[5]]+"Use the Force|r")
 
//*
//* Loop vertically through rows:
//*
        set row = row +1
        set m[col]= row
        if row > 15 then
            set row = mRow
            set col = col +1
//*
//* The main column gets skipped:
//*
            if col != main then
                set col = col +1
            endif
 
            set i = 0
            loop
                set m[i] = mRow
                exitwhen i == 5
                set i = i +1
            endloop
 
            if col > 5 then
                set col = 0
                set mRow = mRow +1
                if mRow > 15 then
                    set mRow = 0
                    set main = main +1
                    if main > 5 then
                        call BJDebugMsg("exhausted")
                        call PauseTimer(GetExpiredTimer())
                        call DestroyTimer(GetExpiredTimer())
                        call StartSound(bj_questSecretSound)
                    endif
                endif
                set m[main] = mRow
            endif
        endif
    endfunction
 
    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(),0.01,true,function Display)
        set m[0] = 0
        set m[1] = 0
        set m[2] = 0
        set m[3] = 0
        set m[4] = 0
        set m[5] = 0
 
        set c[0] = "0"
        set c[1] = "1"
        set c[2] = "2"
        set c[3] = "3"
        set c[4] = "4"
        set c[5] = "5"
        set c[6] = "6"
        set c[7] = "7"
        set c[8] = "8"
        set c[9] = "9"
        set c[10] = "a"
        set c[11] = "b"
        set c[12] = "c"
        set c[13] = "d"
        set c[14] = "e"
        set c[15] = "f"
    endfunction
 
endlibrary
 
Level 5
Joined
Nov 22, 2009
Messages
181
there are websites that do that?
omg sorry.
although part of the question was why it wasn't working. even had i known about the websites there is still an error somewhere or something wrong that i should still find out about and learn how to fix. btw if i had to see it as it was going i could have just put a triggersleepaction in the innermost loop.
 
Last edited:
It is used to destroy groups after doing the actions to them. It is mostly for GUI, things like Pick Every Unit in <Unit Group>. In GUI, you can directly use DestroyGroup() or better yet, group reusing/recycling, whatever you'd like to call it.

Functions like:
JASS:
function ForGroupBJ takes group whichGroup, code callback returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    call ForGroup(whichGroup, callback)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
endfunction

Allow the use for it. But in JASS, you don't need to use that variable.
 
Level 5
Joined
Nov 22, 2009
Messages
181
for the forgroup and forforce functions, what is call back? i mean how do they work and what do they do? Would you use GetEnumUnit() or GetFilterUnit() in the callback function? Would this work?

JASS:
function MoveUnit takes nothing returns nothing
    local unit u = GetEnumUnit()
        call SetUnitPosition(u, 0.00, 3.45)
endfunction
function code takes nothing returns nothing
    local group g = GroupEnumUnitsInRect(g, ARA)
        call ForGroup(g,MoveUnit)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well if you're using ForGroup then it would make GetEnumUnit() available to reference the enumerated unit. The only time that GetFilterUnit() is used is in the boolean expression callback that is required as a parameter when enumerating units.

JASS:
native GroupEnumUnitsInRect takes group whichGroup, rect r, boolexpr filter returns nothing

Notice the boolexpr filter parameter? This will take a boolean expression callback (function that returns a boolean) and within that function you would be able to reference the "enumerating" unit as GetFilterUnit().

Hope this helps.
 
Level 5
Joined
Nov 22, 2009
Messages
181
yeah i noticed that and kind of figured that out already. but that kind of isn't what i really meant. I was wondering how you reference units when using ForGroup. also i wasn't sure if you are even supposed to reference each unit individually or if you are supposed to reference the group as a whole. so which is it again?

so for ForGroup, does callback have to be a boolean expression or is it simply what you want to have happen to the group?
also, is there a ForForce function?
 
Level 5
Joined
Nov 22, 2009
Messages
181
cool thank you.

for structs, when you have a static member, when you set the member, do you use use a single instance member or do you have to use structtype.instanctmember?

do you know what i mean?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Okay, I read this a few pages back and I just wanted to clarify. When you extend an array with a struct it basically allows you to associate data within the array but typically this is a fairly static implementation. Array structs cannot have constructors, as they are neither created nor destroyed. A good use of this is on wc3c.net, with the ARGB library.

kennyman94 said:
for structs, when you have a static member, when you set the member, do you use use a single instance member or do you have to use structtype.instanctmember?

do you know what i mean?

Your description is a little hazy, but a static member is not an instance member and you seem to interchange those words. When you set the static member (either within the declaration line or somewhere else) you do not use an instance member (unless you're setting the static member to the instance member?). Please try to explain a little further, if this does not answer your question:

If you have a static member, let's say:

JASS:
struct example
    static integer dragonRawr
endstruct

In order to reference the static member you do not need an instance of the struct, instead you only need to reference is as (as you said) example.dragonRawr. If you are referencing it from within a static method then you do not need to type example.. Similarly, if you are referencing an instance-member from within an instance-method, you do not need to type this..
 
Level 5
Joined
Nov 22, 2009
Messages
181
ok that answered my question. sorry if that was unclear i seemed unable to phrase it the way i wanted. perhaps i should have used an example.

i used member because (to me) it is still a member of the struct despite not being a member of an instance.

if you were going to have a multiboard, do you think it would be easier to store playerdata (for the multiboard) in a struct, or in a 2d integer array, then use i2s to change the value to string so it can be used in the multiboard?

also is it i2s or I2S?
 
Status
Not open for further replies.
Top