Cokemonkey11
Spell Reviewer
- Joined
- May 9, 2006
- Messages
- 3,570
So learning vJASS in parallel with JASS is the best way to master triggering and scripting using JASS language ?
"best" way perhaps not, but I'd consider it the fastest way
So learning vJASS in parallel with JASS is the best way to master triggering and scripting using JASS language ?
this global block defines a new variable of type filterfunc and it points to that dummy filter which returns true!
what it does is make you pick units with a proper filter insted of null which will create a leak!
scope MyFirst initializer Init
private function Init takes nothing returns nothing
call BJDebugMsg( "|cff32cd32Hello World!!!|r" )
endfunction
endscope
private keyword means that something is only accessible in the scope you are currently coding in.
scope MyFirst initializer Init
private function Init takes nothing returns nothing
call BJDebugMsg( "|cff32cd32Hello World!!!|r" )
endfunction
endscope
function test takes nothing returns nothing
call MyFirst_Init()
endfunction
scope MyFirst initializer Init
public function Init takes nothing returns nothing
call BJDebugMsg( "|cff32cd32Hello World!!!|r" )
endfunction
endscope
function test takes nothing returns nothing
call MyFirst_Init()
endfunction
What's the problem?And yet you left GetEnumUnit() dandling there.
As to the "faster code", people generally say that ForGroup() is slower then this way. I never looked into it, but they both loop through all the group and do your actions, not much of a difference.
huh? GetEnumUnit returns each unit as it is picked... so i dont understand what is wrong with it...And yet you left GetEnumUnit() dandling there.
library A initializer InitA requires B
function InitA takes nothing returns nothing
call StoreInteger(B_gamecache , "a_rect" , Rect(-100.0 , 100.0 , -100.0 , 100 ) )
endfunction
endlibrary
library B initializer InitB
globals
gamecache B_gamecache
endglobals
function InitB takes nothing returns nothing
set B_gamecache=InitGameCache("B")
endfunction
endlibrary
globals
//globals from B:
gamecache B_gamecache
//endglobals from B
//library B:
function InitB takes nothing returns nothing
set B_gamecache = InitGameCache("B")
endfunction
//library B ends
//library A:
function InitA takes nothing returns nothing
call StoreInteger(B_gamecache , "a_rect" , Rect(- 100.0 , 100.0 , - 100.0 , 100))
endfunction
//library A ends
function main takes nothing returns nothing
...
call InitA()
call InitB()
...
endfunction
...
call ExecuteFunc("InitB")
call ExecuteFunc("InitA")
...
EDIT: Omg! ForGroup is as i said at least 2^4 times faster! jass functions are slow but loops are super slow! thats why ForGroup is using c++ coded foreach action! and there u simple have GetEnumUnit which is constant native and you do not need to remove units! since many times you do not want units to be removed!
Since when do pointers leak? Only the pointee (if that's a word) potentially leaks. What do you suggest? call RemoveUnit(GetEnumUnit()) ? That removes the unit from the game, and I think that wouldn't be a good idea.As to GetEnumUnit(), since when do pointers not leak?
local unit u = GetEnumUnit()
//bla bla bla
set u = null
How to use library_once and more imortantly why? why would I want to declare library twice if I know that it will ignore the second declaration ?
globals
integer Int = 12
endglobals
library Bla initializer SetInt
globals
integer Int
endglobals
function SetInt takes nothing returns nothing
local unit u = ...
set Int = GetUnitUserData(u)
endfunction
endlibrary
1) When declaring globals in a library must I use the initializer keyword to make sure that they will run at the top of the script ?
Yes, it's purpose is the same: making sure a certain function specified within the scope is automatically executed when the map loads.2) Can initializer keyword be used in scopes ?
The initializer is also often used to initialize globals that can't otherwise be initialized.
Note: If you use public on a function called InitTrig, it is handled in an special way, instead of becoming ScopeName_InitTrig it will become InitTrig_ScopeName, so you could have an scope/library in a trigger with the same scope name and use this public function instead of manually making InitTrig_Correctname.
Like what, Array variables is an example for that ?
globals
boolexpr b = Filter(function True)
endglobals
Globals can be declared anywhere and are not limited to libraries or scopes. And yes, globals are all merged to the top of the script.So globals with or w/o inititializer will move to the top of the script ?
If you convert a trigger to jass script, you'll probably noticeI don't understand this from JassHelperManual
function InitTrig_TriggerName takes nothing returns nothing
. This function is automatically generated for each specific trigger and acts exactly the way as a library or scope initializer: the function runs when the map loads. This function usually adds the events, conditions and actions to the trigger.public function InitTrig_TriggerName
.scope Blah
public function Blah ...
endfunction
endscope
// becomes
function Blah_Blah ...
endfunction
library nestedtest
scope A
globals
private integer N=4
endglobals
public function display takes nothing returns nothing
call BJDebugMsg(I2S(N))
endfunction
endscope
scope B
globals
public integer N=5
endglobals
public function display takes nothing returns nothing
call BJDebugMsg(I2S(N))
endfunction
endscope
function nestedDoTest takes nothing returns nothing
call B_display()
call A_display()
endfunction
endlibrary
public function outside takes nothing returns nothing
set nestedtest_B_N= -4
call nestedDoTest()
call nestedtest_A_display()
endfunction
call ExecuteFunc("FUNCTIONNAME")
call FUNCTIONNAME()
Nope. Since it's a private global, it can only be read or modified inside the scope (and can't be reached from outside the scope). And while you're inside the scope, you can just write N = VALUE.1) At scope A inside the globals block, N is a private. Now when setting that variable we need to write nestedtest_A_N = VALUE
A_display() will work for sure. I doubt display() will work.2) At scope A, the function diplay() is a public. So outside the scope but inside the library must I call it by A_display() or simply display()
ExecuteFunc allows you to run functions that have not been defined yet at the time of executing it. For example:What is the function of ExecuteFunc or in other word what is the difference between...
function A takes nothing returns nothing
call C() // not allowed since C hasn't been found yet
endfunction
function B takes nothing returns nothing
call ExecuteFunc("C") // This is allowed
endfunction
function C takes nothing returns nothing
call DoNothing()
endfunction
function D takes nothing returns nothing
call C() // this is allowed since C is already defined
endfunction
function Recursive takes nothing returns nothing
call Recursive() // not allowed
endfunction
function RecursiveGood takes nothing returns nothing
call ExecuteFunc("RecursiveGood") // allowed
endfunction
2^4? Want to show some evidence?
Anyway, I find it hard to understand how you know that ForGroup() uses a C++ for loop, and knowing C++ has nothing to do with this.
As to GetEnumUnit(), since when do pointers not leak?
ofc GhostWolf dont take me wrong i was maybe to impolite, its just that i talk like that with people who know how everything is handled but are wrong! since now i understand that u are not one of them! then you have my apologies.
Nope. Since it's a private ..... through ExecuteFunc.
The other way round, .execute is slower but allows TSA to be used.3) .evaluate is slower but also allows TriggerSleepAction to be used.
The other way round, .execute is slower but allows TSA to be used.
And yes, .evaluate and .execute are vJass features.
It's the GUI action "Wait n seconds".What does TriggerSleepAction() do ?
struct pair
integer x
integer y
endstruct
function testpairs takes nothing returns nothing
local pair A=pair.create()
set A.x=5
set A.x=8
call BJDebugMsg(I2S(A.x)+" : "+I2S(A.y))
call pair.destroy(A)
endfunction
local pair A=pair.create()
The other way round, .execute is slower but allows TSA to be used.
And yes, .evaluate and .execute are vJass features.
function somefunc takes nothing returns nothing
call TriggerSleepAction(2.0)
endfunction
call somefunc.execute()
JASS:struct pair integer x integer y endstruct function testpairs takes nothing returns nothing local pair A=pair.create() set A.x=5 set A.x=8 call BJDebugMsg(I2S(A.x)+" : "+I2S(A.y)) call pair.destroy(A) endfunction
1) What do struct do ?
2) Is the struct name is pair or A ?
3) I don't understand this lineJASS:local pair A=pair.create()
structs are used to declare an new type / object in vjass!
that line pair.create() allocates an memory for this two integers x and y
and then as u can see u access members by writing var_name.member
New type / object ? what type and what object ?
So it should be pair.x and pair.y when accessing them![]()
local pair p = pair.create()
set p.x = 5
set p.y = 7
location
variable works: it's just 2 real variables, one for the X coordinate and one for the Y coordinate.struct CharmData
unit u
player p
endstruct
struct CharmData
unit u
player p
endstruct
function CharmEnd takes nothing returns nothing
local timer t = GetExpiredTimer()
local CharmData d = GetTimerData(t) // Retrieve the attached data to the timer
call SetUnitOwner(d.u, d.p, true) // Change owner back into original owner
call ReleaseTimer(t) // Destroy the timer
call d.destroy() // Destroy the CharmData
endfunction
function CharmStart takes unit u, player p returns nothing
// This uses TimerUtils
local CharmData d = CharmData.create() // create new CharmData
local timer t = NewTimer() // If you use TimerUtils, this is the alternative to CreateTimer()
set d.u = u
set d.p = GetOwningPlayer(u)
call SetUnitOwner(u, p, true)
call SetTimerData(t, d) // Attach the charmdata to the timer
call TimerStart(t, 30.0, false, function CharmEnd) // Start the timer, to elapse in 30 seconds
endfunction
// When the spell is cast:
call CharmStart(GetSpellTargetUnit(), GetOwningPlayer(GetTriggerUnit()))
struct CharmData
unit u
player p
endstruct
local CharmData d = GetTimerData(t) // Retrieve the attached data to the timer
CharmData is not a variable its a name for the struct
Yup, that's basically it.CharmData is not the variable but variable type or like a variable type, d is the variable of type CharmData, well that's how I understand it.