$definevariable: Difference between revisions
Jump to navigation
Jump to search

Note:Variables do not work within "quote blocks"!
Note:Variables declared out of the scope of a macro can't be used within the macro. You can pass the data on to the macro by instead using it as a token of the macro and retrieving it that way.
Note:If you define the same variable twice, the compiler will use the first one it finds and drop the second one.
Bug:Similar token prefixes causes the compiler parser to merge, swap, or even ignore some variable values. This doesn't happen with
Source Filmmaker and
Garry's Mod [todo tested in ?]
m (Corrected some incorrect qc script.) |
Trigger hurt (talk | contribs) m (Making use of the "this is a" template for the first line here.) |
||
Line 1: | Line 1: | ||
{{LanguageBar}} | |||
{{this is a|QC command|name=$definevariable}} It creates a {{wiki|variable}}. The variable's name, if surrounded by <code>$</code>, will be substituted by its value whenever encountered. | |||
{{note|Variables do not work within "quote blocks"!}} | {{note|Variables do not work within "quote blocks"!}} | ||
{{note|Variables declared out of the scope of a macro can't be used within the macro. You can pass the data on to the macro by instead using it as a token of the macro and retrieving it that way.}} | {{note|Variables declared out of the scope of a macro can't be used within the macro. You can pass the data on to the macro by instead using it as a token of the macro and retrieving it that way.}} | ||
{{note|If you define the same variable twice, the compiler will use the first one it finds and drop the second one.}} | {{note|If you define the same variable twice, the compiler will use the first one it finds and drop the second one.}} | ||
{{bug|Similar | {{bug|Similar token prefixes causes the compiler parser to merge, swap, or even ignore some variable values. This doesn't happen with {{sfm|4}} and {{gmod|4}}}} | ||
{{bug| | {{bug|Tokens cannot be pushed further than 3 [[$include]] levels}} | ||
This command is | This command is a lighter version of [[$definemacro]]. | ||
== Example == | == Example == |
Revision as of 17:38, 14 July 2024


$definevariable
is a QC command available in all Source games. It creates a
variable. The variable's name, if surrounded by
$
, will be substituted by its value whenever encountered.






This command is a lighter version of $definemacro.
Example
$definevariable baseFile "fighter1"
$sequence attack $baseFile$_Attack // results in -> fighter1_Attack when resolved
$sequence run $baseFile$_Run // results in -> fighter1_Run when resolved
$sequence idle $baseFile$_Idle // results in -> fighter1_Idle when resolved
Here's an example of passing the variable to a macro. We pass $basefile$ to the macro to replace instances of $fightername$
$definevariable baseFile "fighter1"
$definemacro makefighteranim fightername framerate \\
$sequence attack $fightername$_Attack fps $framerate$ \\
$sequence run $fightername$_Run fps $framerate$ \\
$sequence idle $fightername$_Idle fps $framerate$ \\
$makefighteranim $baseFile$ 30 // Here we give "fighter1" from $basefile$ to the macro to be used for $fightername$ token