scope pw initializer onInit
globals
string STRING
string array RANDOM_STRING[2]
integer RANDOM_INTEGER
endglobals
private function pw_Conditions takes nothing returns boolean
if ( not ( GetEnteringUnit() == udg_UNIT ) ) then
return false
endif
return true
endfunction
function pw_Actions takes nothing returns nothing
set RANDOM_STRING[1] = "lol"
set RANDOM_STRING[2] = "lolol"
set RANDOM_INTEGER = GetRandomInt(1,2)
set STRING = RANDOM_STRING[RANDOM_INTEGER]
call DisableTrigger( GetTriggeringTrigger() )
call IssueImmediateOrder( udg_UNIT, "stop" )
call CreateQuestBJ( bj_QUESTTYPE_REQ_DISCOVERED, "PASSWORD", ( "The password is : " + STRING ), "ReplaceableTextures\\WorldEditUI\\Editor-Random-Unit.blp" )
call EnableTrigger( gg_trg_PWT )
call DisplayTextToForce( GetPlayersAll(), STRING )
call DestroyTrigger(GetTriggeringTrigger())
endfunction
//===========================================================================
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterEnterRectSimple( t, gg_rct_PasswordQuest )
call TriggerAddCondition( t, Condition( function pw_Conditions ) )
call TriggerAddAction( t, function pw_Actions )
endfunction
endscope
scope pwt
function pwtactions takes nothing returns nothing
call DisableTrigger( GetTriggeringTrigger() )
set udg_TempPoint[1] = GetRectCenter(gg_rct_PaswordQuestTerain)
call SetTerrainTypeBJ( udg_TempPoint[1], 039;Ydrt039;, -1, 1, 0 )
call DestroyQuest( GetLastCreatedQuestBJ() )
call DisplayTimedTextToForce( GetPlayersAll(), 5.00, "Correct" )
call RemoveLocation(udg_TempPoint[1])
endfunction
function InitTrig_onInits takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i
loop
exitwhen i>11
call TriggerRegisterPlayerChatEvent(t, Player(i), STRING, true)
set i=i+1
endloop
call TriggerAddAction(t, function pwtactions)
endfunction
endscope
call DisplayTextToForce( GetPlayersAll(), STRING )
JassHelperManual said:Private members
With the adition of libraries it was a good idea to add some scope control, private members are a great way of protecting users from themselves and to avoid collisions.
The scope keyword has this syntax: scope NAME [...script block...] endscope
So, functions and other declarations inside an scope can freely use the private members of the scope, but code outside won't be able to.
scope global initializer init
globals
string STRING
integer RANDOM_INTEGER
string array RANDOM_STRING[2]
endglobals
private function init takes nothing returns nothing
set RANDOM_STRING[0] = "lol"
set RANDOM_STRING[1] = "lolol"
set RANDOM_INTEGER = GetRandomInt(0,1)
set STRING = RANDOM_STRING[RANDOM_INTEGER]
endfunction
endscope
scope pw initializer onInit
private function pw_Conditions takes nothing returns boolean
if ( not ( GetEnteringUnit() == udg_ChosenHero ) ) then
return false
endif
return true
endfunction
function pw_Actions takes nothing returns nothing
call DisableTrigger( GetTriggeringTrigger() )
call IssueImmediateOrder( udg_ChosenHero, "stop" )
call CreateQuestBJ( bj_QUESTTYPE_REQ_DISCOVERED, "PASSWORD", ( "The password is : " + STRING ), "ReplaceableTextures\\WorldEditUI\\Editor-Random-Unit.blp" )
call EnableTrigger(gg_trg_p)
call DisplayTextToForce( GetPlayersAll(), STRING )
call DestroyTrigger(GetTriggeringTrigger())
endfunction
//===========================================================================
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterEnterRectSimple( t, gg_rct_PasswordQuest )
call TriggerAddCondition( t, Condition( function pw_Conditions ) )
call TriggerAddAction( t, function pw_Actions )
endfunction
endscope
function Trig_p_Actions takes nothing returns nothing
call DisableTrigger( GetTriggeringTrigger() )
set udg_TempPoint[1] = GetRectCenter(gg_rct_PaswordQuestTerain)
call SetTerrainTypeBJ( udg_TempPoint[1], 039;Ydrt039;, -1, 1, 0 )
call DestroyQuest( GetLastCreatedQuestBJ() )
call DisplayTimedTextToForce( GetPlayersAll(), 5.00, "Correct" )
call RemoveLocation(udg_TempPoint[1])
endfunction
//===========================================================================
function InitTrig_p takes nothing returns nothing
set gg_trg_p = CreateTrigger( )
call TriggerRegisterPlayerChatEvent(gg_trg_p, Player(0), STRING, true)
call TriggerAddAction( gg_trg_p, function Trig_p_Actions )
endfunction
scope password initializer init
globals
private trigger Trigger = CreateTrigger()
private region Region = CreateRegion()
private quest Quest // Don't rely on something like GetLastCreatedQuest()
endglobals
private function onChat takes nothing returns boolean
call SetTerrainType(GetRectCenterX(gg_rct_PaswordQuestTerain), GetRectCenterY(gg_rct_PaswordQuestTerain), 039;Ydrt039;, -1, 1, 0)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0., 0., 5., "Correct")
// ----
// Clear leaks
call DestroyTrigger(GetTriggeringTrigger())
call DestroyQuest(Quest)
call RemoveRect(gg_rct_PaswordQuestTerain)
set gg_rct_PaswordQuestTerain = null
set Quest = null
return false
endfunction
private function onEnter takes nothing returns boolean
local string s
local trigger t
if GetFilterUnit() == udg_ChosenHero then
call IssueImmediateOrder(udg_ChosenHero, "stop")
if GetRandomInt(1, 2) == 1 then
set s = "lol"
else
set s = "lolol"
endif
call DisplayTextToPlayer(GetLocalPlayer(), 0., 0., s)
set Quest = CreateQuestBJ(bj_QUESTTYPE_REQ_DISCOVERED, "PASSWORD", "The password is : " + s, "ReplaceableTextures\\WorldEditUI\\Editor-Random-Unit.blp")
set t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t, Player(0), s, true)
call TriggerAddCondition(t, Condition(function onChat))
// ----
// Clear leaks
call DestroyTrigger(Trigger)
call RemoveRegion(Region)
set Trigger = null
set Region = null
set t = null
endif
return false
endfunction
private function init takes nothing returns nothing
call RegionAddRect(Region, gg_rct_PasswordQuest)
call TriggerRegisterEnterRegion(Trigger, Region, Condition(function onEnter))
// ----
// Clear leaks
call RemoveRect(gg_rct_PasswordQuest)
set gg_rct_PasswordQuest = null
endfunction
endscope