AlicanC
New Member
- Reaction score
- 2
I am trying to code a set of functions to make adding commands like "-<commandname> <parameter>" easier.
Here is the functions I use:
and when I try to use those functions like this:
I get these errors:
My system was working perfectly before I collected all functions (Event, condition, action) in "CreateCommandTrigger()". I think there is a problem with the way I take a function as a parameter ("code conditionFunction"). How can I fix this?
Thanks in advance,
AlicanC.
Here is the functions I use:
JASS:
//Conditions
function CONDITION_NONE takes nothing returns boolean
return true
endfunction
function CONDITION_HOSTONLY takes nothing returns boolean
//Host only
if not(GetTriggerPlayer()==udg_nv_Host) then
return false
else
return true
endif
endfunction
function CONDITION_MODE takes nothing returns boolean
//Mode
if udg_nv_WaitingForModes==false and not(GetTriggerPlayer()==udg_nv_Host) then
return false
else
return true
endif
endfunction
//GetParameter
function GetParameter takes string whichString, string whichCommand returns string
return StringCase(SubString(whichString, StringLength(whichCommand)+2, StringLength(whichString)), false)
endfunction
//TriggerRegisterPlayerCommand
function TriggerRegisterPlayerCommand takes trigger whichTrigger, string whichCommand, boolean takesParameter, integer startPlayer, integer endPlayer returns nothing
//Locals
local integer i
local string chatMessageToDetect
local boolean exactMatchOnly
set i= startPlayer
if takesParameter==false then
set chatMessageToDetect= "-"+whichCommand
set exactMatchOnly= true
else
set chatMessageToDetect= "-"+whichCommand+" "
set exactMatchOnly= false
endif
//TriggerRegisterPlayerChatEvent
loop
exitwhen i>endPlayer
call TriggerRegisterPlayerChatEvent(whichTrigger, Player(i), chatMessageToDetect, exactMatchOnly)
set i= i+1
endloop
//Nullify
set chatMessageToDetect= null
endfunction
//CreateCommandTrigger
function CreateCommandTrigger takes trigger commandTrigger, string whichCommand, boolean takesParameter, code conditionFunction, code actionFunction returns nothing
//Create trigger
set commandTrigger= CreateTrigger()
//Events
call TriggerRegisterPlayerCommand(commandTrigger, whichCommand, takesParameter, 0, 11)
//Conditions
call TriggerAddCondition(commandTrigger, Condition(conditionFunction))
//Actions
call TriggerAddAction(commandTrigger, actionFunction)
endfunction
and when I try to use those functions like this:
JASS:
function Trig_Test_Actions takes nothing returns nothing
//Locals
local string parameter
set parameter= GetParameter(GetEventPlayerChatString(), "test")
//Show parameter
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 2, "Parameter is: 039;"+parameter+"039;.")
//Nullify
set parameter= null
endfunction
//===========================================================================
function InitTrig_Test takes nothing returns nothing
//Create command trigger
call CreateCommandTrigger(gg_trg_Test, "test", true, CONDITION_NONE, Trig_Test_Actions)
endfunction
I get these errors:
Code:
Undeclared variable CONDITION_NONE
Undeclared variable Trig_Test_Actions
Thanks in advance,
AlicanC.