• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Few Questions

Status
Not open for further replies.
Level 18
Joined
Jan 21, 2006
Messages
2,552
It's possible with either case, since a struct that extends an array is just an associated parallel array, to which adding struct recycling would yield the exact same result as normal structs.

You could also add a method operator [] takes integer index returns thistype which would allow you to create a 2D array interface for referencing multiple player multiboards.
 
Level 5
Joined
Nov 22, 2009
Messages
181
berbanog, can you explain what you mean with the last post?

and thanks. i was just wondering wich you guys think is easier.

for multiboarditems, when you want one to be displayed after you set the value, do you first have to release the multiboarditem? or does it automatically update as it is changed?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
kennyman94 said:
berbanog, can you explain what you mean with the last post?

Are you familiar with vJass?

kennyman94 said:
for multiboarditems, when you want one to be displayed after you set the value, do you first have to release the multiboarditem? or does it automatically update as it is changed?

Releasing the multiboard item does something internally that allows you to repeat these actions. If you change a multiboard item I believe that it is updated immediately.
 
Level 5
Joined
Nov 22, 2009
Messages
181
what do you mean by "repeat these actions"?

and yes i read the entire jasshelper manual.

i mean i know things like structs and methods. im not very good mind you but i understand the concepts. although i dont really understand the point of interfaces.and i understand operatoroverriding. i kind of meant what would that operator method be used for and how would it work.
 
A method operator is just a function call with a parameter, with a syntax that allows for less obstructive coding.

JASS:
method operator hai= takes real x returns nothing
    call BJDebugMsg(R2S(x))
endmethod
//...
set hai=3.14159

That's pretty much the same as:

JASS:
function hai takes real x returns nothing
   call BJDebugMsg(R2S(x))
endfunction
//...
call hai(3.14159)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Method operators can also only have the same amount of arguments as the operator that you're using. For example, if you are using the []= operator then you can have one parameter for the array bounds (which doesn't have to be an integer) and a parameter for the assignment, which comes after the =.
 
Level 5
Joined
Nov 22, 2009
Messages
181
If I wanted to add an action/condition to a trigger, can I use a method instead of a function? if so what would the correct syntax be?
 
Level 5
Joined
Nov 22, 2009
Messages
181
Does the method have to be static if you are going to use it as an action or condition and if you are you still able to use instance members withim that method? lets say you have this:
JASS:
struct sdb
    //other members
    static region e = CreateRegion()
endstruct
would it reset and override the regin if i added a rect to the region then created a new instance?
 
Yes; the only difference between "method" and "static method" is that method takes a hidden variable called "this" (you don't see that it takes this variable, but when you look in the war3map.j file you'll see it's compiled with a "this" parameters).

Anyway, functions with parameters do not work for "code"-type arguments, so consider that. If you feel you are typing too much, you should jump on Zinc, which eliminates a lot of typing and creates some extremely awesome shortcuts.
 
I don't know about that, berb, when

JASS:
library Zinc
{
    group grp = CreateGroup(); integer count;
    
    function onInit()
    {
        trigger t = CreateTrigger();
        TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT);
        TriggerAddAction(t,function ()
        {
            unit u;
            real a,x1,y1,z1,x2,y2,z2;
            
            count = 0; ForGroup(grp,function () { count += 1; BJDebugMsg(I2S(count)); });
            
            u = null;
        });
    }
}

Is a lot easier to type, easier to organize, and helps familiarize yourself with professional C-syntax, compared to:

JASS:
library vJass initializer Init

globals
    private group grp = CreateGroup()
    private integer count
endglobals

    private function GroupEnum takes nothing returns nothing
        set count = count + 1
        call BJDebugMsg(I2S(count))
    endfunction
    
    private function Group takes nothing returns nothing
        local unit u
        local real a
        local real x1
        local real y1
        local real z1
        local real x2
        local real y2
        local real z2
        set count = 0
        call ForGroup(grp,function GroupEnum)
        set u = null
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddAction(t,function Group)
    endfunction

endlibrary
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I don't make useless functions like the one you posted. The only times I ever add to a group it is already known by variable reference how many are in the group. If not I would never use a function to find that out for me.
 
JASS:
call ForGroup(g,function enumerate)
native ForGroup takes group whichGroup, code callback returns nothing
// code is a primitive type.

// this means that "enumerate" must "take nothing return nothing", otherwise
// it's an invalid argument.  The only time a code can return a value is in a
// boolean expression, where it must return true or false:

set expression = Condition(function verify)
native Condition takes code func returns conditionfunc
type conditionfunc      extends     boolexpr
type boolexpr           extends     agent
type agent			    extends     handle
// handle is a primitive type.

Not sure I follow; every trigger is automatically "MUI" until you include a TriggerSleepAction.
 
Level 5
Joined
Nov 22, 2009
Messages
181
so can i use polled wait or no? and can you make a trigger with a wait mui by having another trigger that creates a trigger for the triggering unit?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Yea just use a stack with a periodic timer. Add elements to the stack as you need the periodic actions, and in the periodic trigger perform all of the actions necessary by looping through each index of the stack.
 
Might want to first start off with hashtables... Just to get the basics of MUI.

Then TimerUtils -> KT2/Struct Loops/Stack Loops (High freq) -> T32/Lists (High freq)

Progressively your code will become more efficient. If you know some stuff about structs, jumping to TimerUtils red/orange is fine, as its coding is pretty simple with NewTimer() / ReleaseTimer().

Read up on this post:
http://www.hiveworkshop.com/forums/1589982-post3.html

It has some nice examples of the latest timer systems.
 
Level 5
Joined
Nov 22, 2009
Messages
181
ok thank you.

does the trigger event
JASS:
EVENT_PLAYER_UNIT_SELL
refer to when a unit owned by a player purches a unit from a structure like a hero tavern or does it refer to when a structure owned by a player sells a unit to another player?

so basically would GetTriggeringUnit() refer to the buying unit or the selling unit?

ok stacking seems very confusing. probably since i don't know c and that is what the examples seem to be in.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
In JASS GetTriggerUnit always refers to the logical associated unit based on the event-name. In this case, I believe it would refer to the unit that sold the purchased unit. In GUI the names are a little skewed, but if you're ever unsure you can always do:

JASS:
call BJDebugMsg(GetUnitName(GetTriggerUnit()))

This will let you know what unit is being referenced. If there is no unit, you will know because it will display "(null)".
 
Level 5
Joined
Nov 22, 2009
Messages
181
ok thanks. i guess i could do that. so should i use:
JASS:
TriggerRegisterPlayerUnitEvent(t, Player(15), EVENT_PLAYER_UNIT_SELL, null)
to register when a hero is bought from a hero tavern (owned by neutral passive player)?
 
Last edited:
Level 5
Joined
Nov 22, 2009
Messages
181
Are you familiar with vJass?



Releasing the multiboard item does something internally that allows you to repeat these actions. If you change a multiboard item I believe that it is updated immediately.

so basically you can only change the value of a multiboard item once without fiirst releasing then getting the item again?

is there a way to detect whenever a variable within a struct has been set to a new value and use the instance member that was set within a seperate struct or function?

also can you hook method operators?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
also can you hook method operators?

A method operator is an instance-method. An instance method requires an instance, in this case an integer struct. When a native function is called (the functions that can be hooked) there is no integer index, or no "instance", so how exactly would that work?

There may be static method hooks, but that's only because a static method is pretty much a function with different keywords.

So, wait, you knew what a method operator was before asking this question? Personally that is the very first thing I used it for. It's basically just another way of "transforming" the interface of your code so that it is easy and understandable.
 
You could always manually hook it:
JASS:
//this doesn't make much sense
globals
    trigger hookOp_x = CreateTrigger() //trigger for hooking
    integer sTempFun = 0 //temporary instance for passing data
endglobals

struct Fun
    real asdf 
    method operator x takes nothing returns real
        return this.asdf
    endmethod   
    method operator x= takes real value returns nothing
        set this.asdf = value //set this.asdf to the value input
        set sTempFun = this //set the tempData global to this instance
        call TriggerEvaluate(hookOp_x) //evaluate the hook
    endmethod
endstruct

function onhookX takes nothing returns boolean //example function for hooking
    call BJDebugMsg("X-Value: "+R2S(Fun(sTempFun).x)) //should read "5" in this case
    return false //return false, since it is a condition
endfunction

function blahblah takes nothing returns nothing
    call TriggerAddCondition(hookOp_x,Condition(function onhookX)) //add this func to the hooking
    set Fun(1).x=5 //modify the value to evaluate the hook
endfunction

But even then, it is a little weird. :p Usually you are in control when the value changes anyway. And knowing when it changes is usually what variable method operators are for, aside from simplification of interface. ;)

Btw, that was just an example, it should work but I'm not positive. Still, tell us what you need it for and there is most likely a workaround.
 
Level 5
Joined
Nov 22, 2009
Messages
181
So, wait, you knew what a method operator was before asking this question? Personally that is the very first thing I used it for. It's basically just another way of "transforming" the interface of your code so that it is easy and understandable.

I knew what operatorator overriding was but i wasn't exactly sure what it was used for. all i knew was that it could let you change the function of an operator.

So what exactly is the typecast operator? and what is the syntax?

i know that array structs can't have array members but can an array struct have a struct with an array member like:
JASS:
struct Stats
    integer array stat[21]
    integer array wins[12]
    integer array losses[12]
endstruct
struct P extends array
    Stats s = 0
    method Init takes nothing returns nothing
        set .s = s.create()
    endmethod
endstruct
//note:that is not the only part of it. i have a lot more stuff 
//but for the purposes of this example am only using those 2 structs

so no, you can't hook methods or method operators?

what do symbol do you use for modulo?

if an id is an integer then why are there letters in it? is it hex because i thought hex only went from 0 - f and ive seen characters other that those. and what is with the ' ' delimiters?
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
so no, you can't hook methods or method operators?

You can only hook native functions. The hook callback can either be a static method or a function, I believe.

what do symbol do you use for modulo?

There is no modulo operator.

if an id is an integer then why are there letters in it?

Well a character is more or less an integer and there are non-numeric values in those.

is it hex because i thought hex only went from 0 - f

No, I believe it's actually ASCII.

and what is with the ' ' delimiters?

Well those delimiters indicate that the included text is to be converted to an integer. It is used on characters for dialog hot-keys as well. If you do call BJDebugMsg(I2S('c')) I believe it will return the ASCII character ID for "c".
 
Level 5
Joined
Nov 22, 2009
Messages
181
ok and what was with the copied post?

what is ASCII?

then what do you use for modulo?

and you never answered the first question of that post. or the second.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
What the hell? I didn't realize that... must have been a lag glitch. I'll remove the second one now.

what is ASCII?

What is Google?

then what do you use for modulo?

A combination of subtraction and integer division. Either that or you can use the crappy ModuloReal and ModuloInteger functions.

and you never answered the first question of that post. or the second.

So what exactly is the typecast operator? and what is the syntax?

This question? What the hell is a "typecast operator"? An operator is a symbol that performs specified actions. For example, an array uses the [] operator in order to reference a specific index of the storage reference. You can reroute this functionality to have it do something different (typically used when the type does not already provide that type of functionality).

So, please explain yourself a little more clearly.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
i know that array structs can't have array members but can an array struct have a struct with an array member like:

If you try to give an array-struct an array member it will tell you that you're not allowed. Why don't you just try to compile it and see if it's working correctly. You can also check the JassHelper manual to determine if it is a feature of JassHelper.

In fact, if you try to compile it then the parser will tell you "use a dynamic array instead if necessary", which is exactly what you posted.

JASS:
struct strarray2
    integer array i [2]
endstruct
struct strarray extends array
    strarray2   b
endstruct

This is perfectly acceptable. Keep in mind that there can only be 8191/2 instances of strarray2, which will in turn limit the amount of strarray instances there can be.
 
Status
Not open for further replies.
Top