Wassup wrote:When I used a macro with /varset VarName 15, and then used $defined(@VarName), FALSE was returned.
Code: Select all
/varset VarName 15
/echo $defined(@VarName)
How is this handled by the parser, you ask? The @VarName is changed to its value by the parser *before* the $defined operator is run. So, effectively you have done this
which should return false.
How would you evaluate this?
Code: Select all
/varset VarName Param0
/echo $defined(@VarName)
Now, wrap your brain around Plaz's test macro:
Code: Select all
#event Test "custom test"
#event Test2 "custom test"
Sub Main(TestParam)
/echo UserVarsTest - Start
/echo
/echo TEST: Parameters - Start
/if $defined(TestParam)==FALSE {
/echo Please pass in 2 parameters
/return
}
/if $defined(Param1)==FALSE {
/echo Please pass in 2 parameters
/return
}
/echo Two parameters passed in: '@TestParam' and '@Param1'
/echo TEST: Parameters - End
/echo
/echo TEST: Case Sensitivity - Start
/declare MyGlobal global
/varset MyGlobal gtest
/echo $defined(MyGlobal) should be TRUE
/echo $defined(Myglobal) should be FALSE
/echo '@MyGlobal' should be 'gtest'
/echo '@Myglobal' should be '²Myglobal'
/echo TEST: Case Sensitivity - End
/echo
/echo TEST: Dereference - Start
/declare Loc1 local
/declare Loc2 local
/declare Loc3 local
/declare Loc4 local
/varset Loc1 Loc2
/varset Loc2 Loc3
/varset Loc3 Loc4
/varset Loc4 MyGlobal
/echo '@Loc1' should be 'Loc2'
/echo '@@Loc1' should be 'Loc3'
/echo '@@@Loc1' should be 'Loc4'
/echo '@@@@Loc1' should be 'MyGlobal'
/echo '@@@@@Loc1' should be '@MyGlobal'
/echo TEST: Dereference - End
/echo
/echo TEST: For 1 to 5 - Start
/declare MyLoc local
/varset Loc1 ""
/for MyLoc 1 to 5
/varset Loc1 "@Loc1 @MyLoc"
/next MyLoc
/echo '@Loc1' should be ' 1 2 3 4 5'
/echo TEST: For 1 to 5 - End
/echo
/echo TEST: /var... functions - Start
/echo MyLoc: '@MyLoc'
/varsub MyLoc 2
/echo MyLoc-2: '@MyLoc'
/varadd MyLoc 3
/echo MyLoc+3: '@MyLoc'
/varcalc MyLoc @MyLoc*10
/echo MyLoc*10: '@MyLoc'
/echo TEST: /var... functions - End
/echo
/echo TEST: 1D Array - Start
/declare MyArray array
/varset MyArray(2) test1d
/echo '@MyArray(2)' should be 'test1d'
/echo TEST: 1D Array - End
/echo
/echo TEST: 2D Array - Start
/declare TwoArray array2
/varset TwoArray(5,2) test2d
/echo '@TwoArray(5,2)' should be 'test2d'
/echo TEST: 2D Array - END
/echo TEST: Sub Named Parameters - Start
/if $defined(blahblah)==TRUE /echo blahblah should not be defined!
/call paramtest @blahblah lala @MyGlobal
/echo TEST: Sub Named Parameters - End
/echo
/echo TEST: Timer - Start
/declare MyTimer timer
/varset MyTimer 1s
/varset MyGlobal 0
:Loop
/doevents
/if n @MyGlobal==0 /goto :Loop
/echo TEST: Timer - End
/echo
/echo TEST: Custom events - Start
/echo Trigger: custom test
/doevents
/echo 2 events should have fired
/echo TEST: Custom events - End
/echo
/echo UserVarsTest - End
/return
Sub paramtest(blahblah,MyTimer,LastVar)
/echo Sanity: '@LastVar' should be '@MyGlobal'
/echo Resursive: '@blahblah' should be '²blahblah'
/echo Scope masking: '@MyTimer' should be 'lala'
/return
Sub Event_Timer(Timer,Original)
/echo @Timer fired
/varset MyGlobal 1
/return
Sub Event_Test
/echo this event test has no params defined
/return
Sub Event_Test2(Message)
/echo this event test did have params defined.
/return