method operator [] takes integer index returns thistype
which would allow you to create a 2D array interface for referencing multiple player multiboards.kennyman94 said:berbanog, can you explain what you mean with the last post?
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?
method operator hai= takes real x returns nothing
call BJDebugMsg(R2S(x))
endmethod
//...
set hai=3.14159
function hai takes real x returns nothing
call BJDebugMsg(R2S(x))
endfunction
//...
call hai(3.14159)
[]=
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 =
.call TriggerAddCondition(t,Condition(function thistype.Conditions))
// or in zinc, we have something that makes more sense:
TriggerAddCondition(t,Condition(static method thistype.Conditions))
struct sdb
//other members
static region e = CreateRegion()
endstruct
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;
});
}
}
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
what do you mean by that?functions with parameters do not work for "code"-type arguments
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.
TriggerSleepAction
.NewTimer()
/ ReleaseTimer()
. EVENT_PLAYER_UNIT_SELL
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:call BJDebugMsg(GetUnitName(GetTriggerUnit()))
TriggerRegisterPlayerUnitEvent(t, Player(15), EVENT_PLAYER_UNIT_SELL, null)
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.
struct Fun
real var
method myFunc takes nothing returns nothing
//do your stuff
endmethod
method operator var= takes real value returns nothing
set this.var = value //set the value
call this.myFunc() //call your function
endmethod
endstruct
also can you hook method operators?
//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
And knowing when it changes is usually what variable method operators are for, aside from simplification of interface
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.
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 what is with the ' ' delimiters?
call BJDebugMsg(I2S('c'))
I believe it will return the ASCII character ID for "c".what is ASCII?
then what do you use for modulo?
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?
[]
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).i figured. but okA combination of subtraction and integer division. Either that or you can use the crappyModuloReal
andModuloInteger
functions.
i know that array structs can't have array members but can an array struct have a struct with an array member like:
struct strarray2
integer array i [2]
endstruct
struct strarray extends array
strarray2 b
endstruct
strarray2
, which will in turn limit the amount of strarray
instances there can be.